How to tell if (X,Y) coordinate is within a Circle

6.4k Views Asked by At

Lets say we have a circle on a MxN grid as shown below.

How can we determine whether the coordinate X,Y falls within the circles coordinates under the assumptions?

  • We know the diameter of the circle
  • We know that the circle will be always centered!

Example of Circle and Grid

1

There are 1 best solutions below

5
On BEST ANSWER

The general equation of a circle with radius $R$ and origin $(x_0, y_0)$ is $$ (x-x_0)^2+(y-y_0)^2=R^2 \quad (*) $$ You can derive it from Pythagoras theorem on the sides of a triangle with one rectangular angle $a^2+b^2=c^2$.

Example for a circle with origin $(0,0)$:

example

If a point $(x,y)$ is within the circle, you can interpret it as lying on a circle with smaller radius $r$ and the same origin. As $r<R$ this implies $r^2<R^2$. It fulfills $$ (x-x_0)^2+(y-y_0)^2=r^2 < R^2 = (d/2)^2 = d^2/4 $$ where $d = 2R$ is the diameter of the circle. So for interior points equation $(*)$ turns into an inequality with $<$ relation.