Find the points on circumference of a circle

25 vues (au cours des 30 derniers jours)
arun Dhillon
arun Dhillon le 10 Oct 2019
Réponse apportée : Matt J le 10 Oct 2019
How can I find all the x,y coordinates on the circumference of the circle; if I know the center of the circle and the radius of the circle. So in other words; imagine I have a circle in an image with its centre at 500,500. I know that the radius of this circle is 50 pixels. How can I find all the x,y coordinates that will be on the circumference of that circle. Further, the size of the image is 1280*720 pixels. Any suggestions or help is greatly appreciated.
  2 commentaires
Matt J
Matt J le 10 Oct 2019
A circle will not generally pass through the exact centers of pixels in an image. You will need to specify some kind of rule to decide whether a pixel is close enough to the circumference to be considered "on it".
arun Dhillon
arun Dhillon le 10 Oct 2019
Okay Considering 5 pixels + or - for the inaccuracy to find all the x,y, points on the circumference; how can I find even those.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 10 Oct 2019
Use sind() and cosd() to get all the x and y coordinates. Round them to get integers and use unique() with the rows option to remove duplicates. Try this:
radius = 50
xCenter = 500;
yCenter = 500;
rows = 720
columns = 1280
theta = linspace(0, 360, 4*pi*radius); % More than needed to avoid gaps.
x = xCenter + radius * cosd(theta);
y = yCenter + radius * sind(theta);
grayImage = 128 * ones(rows, columns, 'uint8');
xy = round([x', y']);
xy = unique(xy, 'rows');
x = xy(:, 1);
y = xy(:, 2);
for k = 1 : length(x)
grayImage(y(k), x(k)) = 255;
end
imshow(grayImage);
axis('on', 'image');
fprintf('Done!\n');
0000 Screenshot.png

Plus de réponses (1)

Matt J
Matt J le 10 Oct 2019
Okay Considering 5 pixels + or - for the inaccuracy to find all the x,y, points on the circumference; how can I find even those.
Dsq=( (1:1280).'-500 ).^ + ((1:720)-500).^2;
idx = (Dsq>=(50-5).^2) & (Dsq<=(50+5).^2) ;
[X,Y]=ndgrid(1:1280,1:720);
CircumferencePixels=[X(idx), Y(idx)];

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by