2

Let us say I have a grid of 1000 x 1000, and on that grid is drawn a circle, the circle could be anywhere.

If I then pick a random point from the grid with an x and y co-ordinate I can work out if the point is inside the circle by performing the following math,

xCoord = x co-ordinate;
yCoord = y co-ordinate;
xCenter = x co-ordinate of the center of the circle
yCenter = y co-ordinate of the center of the circle
radius = the circle's radius

((xCoord - xCenter) ^ 2 + (yCoord - yCenter) ^ 2) < (radius ^ 2)

If the radius ^ 2 is less than ((xCoord - xCenter) ^ 2 + (yCoord - yCenter) ^ 2) then it means that the co-ordinates were inside the circle.

I am struggling alot to wrap my head around this and cannot seem to work out how it works out that the co-ordinates were inside the circle.

Could someone please break this down for me and explain how it is worked out (what is going on in a logical manner so to speak)?

Sorry if my question is formatted wrong it is my first question on this site.

Thanks

CarlG
  • 123
  • As written, your formula actually states that if radius squared is greater than ((xCoord - xCenter) ^ 2 + (yCoord - yCenter) ^ 2), then the point is inside the circle. It should make more sense that way. ("$a<b$" means $a$ less than $b,$ which is the same as $b$ greater than $a$.) – Will Orrick May 09 '13 at 17:14

2 Answers2

2

Let $(x_0,y_0)$ be the centre of the circle with radius $r$. Then your formula says that the point $(x,y)$ is inside the circle if $$(x-x_0)^2+(y-y_0)^2<r^2$$

[$r^2$ is greater than $(x-x_0)^2+(y-y_0)^2$, not less than as the un-quoted text in your question says.]

Now, this works because the distance between the point $(x,y)$ and $(x_0,y_0)$ is given by $\sqrt{(x-x_0)^2+(y-y_0)^2}$, by the Pythagoras Theorem. (This is a helpful image to illustrate this.)

So all your formula is saying is that if the distance between the point and centre of the circle is less than the radius, the point is inside the circle. This should be obvious.

Milind Hegde
  • 3,914
1

Let me try to answer in words only. you have a circle. To fill it in, as with a paint program, it's every point whose distance from the center of the circle is less than the radius of the circle. Simple enough.

To test if a point is inside the circle, calculate the distance from the center point to your point. If less than the radius, it's in your circle.