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

Re: [pygame] collision detection



> I think there is a nice FAQ for comp.graphics that you really ought to
> go read.
>
> Alternatively, a regular polygon with many sides is a good
> approximation to a circle.
>
> -a


The solution is VERY easy for a circle...

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.