Posted by: swpalmer Posted on: Feb 5th, 2004, 1:20am
If these are perfect circles then a simple test of the square distance between the center of the circles is enough.
(dx*dx + dy*dy) <= (r1*r1 + r2*r2)
Actually I think this may be off by a bit. You want to check if the distance between the centers is less than the sum of the radii, and do so by comparing their squares to avoid taking roots for efficiency. The left side is the square of the distance, but the right side is the sum of the squares of the radii -- not the square of the sum of the radii.
Somebody correct me if I'm wrong, but I think the RHS should be (r1*r1 + 2*r1*r2 + r2*r2).
Minor point... unless your objects are penetrating each other and making your application look bad....