Possible Duplicate:
How do you test if a point is inside a circle?
I need a way to determine if point P is inside circle C defined by a center point and a radius.
Is there an algorithm for this?
Thanks
Possible Duplicate:
How do you test if a point is inside a circle?
I need a way to determine if point P is inside circle C defined by a center point and a radius.
Is there an algorithm for this?
Thanks
Yes, and the algorithm is quite simple. Just check if the distance from the point P to the center of the circle C is less than the radius of the circle.
Of course there is:
The point is inside if the distance from the center to the point is less than the circle's radius.
As a silly optimization, if you need to do this a lot and the circles are more or less constant, compare to the square of the circle's radius to shave some time from the computation (since computing the distance involves computing the square root, which is more expensive than not doing so).
Compute the distance between P and the center of the circle. If the distance is less than the radius, your point is inside the circle. Sounds easy!