Determining if a point is within a circle
Hey guys,
I have need to write an applet that does the following:
1. Draws a circle
2. When a user clicks anywhere inside the circle and drags the mouse to
a different location the circle should be redrawn in that location when mouse is released.
My question is:
How do you determine weather a mouse click occurred within a circle? I think the question is rather mathematical, basically how to check if a point
A(x, y) is inside a circle.
Thanks for your help
[516 byte] By [
_grinch_a] at [2007-11-26 18:51:04]

Hiwa already gave you the Java solution, but, in case you're wondering, the point is inside the circle if the distance between the point and the center of the circle is less than the radius of the circle.
So, assuming you have the following information.
Center of circle: xc, yc
Radius of circle: r
Point: xp, yp
if (xc - xp)^2 + (yc -yp)^2 < r^2 then the point is in the circle.
(Note that if you try to do this in Java, ^ is NOT a power operator.)
> Hey guys,
> I have need to write an applet that does the
> following:
> 1. Draws a circle
> 2. When a user clicks anywhere inside the circle and
> drags the mouse to
> a different location the circle should be redrawn in
> that location when mouse is released.
>
> My question is:
> How do you determine weather a mouse click occurred
> within a circle? I think the question is rather
> mathematical, basically how to check if a point
> A(x, y) is inside a circle.
>
> Thanks for your help
You click on a point (xi, yi); then, if the distance between the origin of the circle and (xi, yi) is less than the radius of the circle you are golden.