views:

399

answers:

4

We have a point (x,y) and some other points (xi,yi). How can we determine wich of (xi,yi) points are within a circle with center (x,y) and radius d (a given number) Thanks

+2  A: 

Simple way.

Compute the distance from the point to the center of the circle. If less than radius , then its within the circle.

Andrew Keith
+2  A: 

If sqrt((xi-x)^2 + (yi-y)^2) <= d

Jose M Vidal
you can optimize this. Ommit the SQRT for better performance.(xi-x)^2 + (yi-y)^2 <= d ^2
Andrew Keith
+6  A: 
(xi-x)**2 + (yi-y)**2 < r**2
ZZ Coder
+1 because you avoid the square root.
ntd
+2  A: 

If (xi - x)^2 + (yi - y)^2 is less than d^2, it's inside. If it equals d^2, it's on the circle. If it's greater than d^2, it's outside.

John at CashCommons