[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] collision detection



hi

The solution is VERY easy for a circle...
of course it is easy!.
jesus, i must go back to my primary school books ...
thanks


Point P, with coord Px, Py

Circle C, with Center Cx, Cy, and Radius R.

If sqrt((Cx-Px)^2 + (Cy-Py)^2) <R, then the point is within the circle. The part in front of the '<' is simply the formula for finding the distance between two points.

One can drop the expensive SQRT op, and say (Cx-Px)^2 + (Cy-Py)^2 < R^2

IE, if the distance between P and C is < R, than the point is inside the circle.

If it = R, the point is on the edge of circle, and well, it's a design choice as to whether that counts as inside/outside the circle.




--
enrike