how to detect collison between a circle and a block?

366 views Asked by At

Possible Duplicate:
Circle-Rectangle collision detection (intersection)
How to determine the collision of a circle with a rectangle?

I want to detect the intersection or collision of a circle with an generaly positioned block. The block is rectangular and may be any size or rotation.

What is the math behind this?

1

There are 1 answers

0
Joseph O'Rourke On BEST ANSWER

Write one function that checks if an arbitrary segment ab intersects a circle C. Write a second function that checks if a point p is inside a circle C. Then call the 1st function four times, for the four rectangle sides, and if all those fail, call the 2nd function on one corner (to check if the rectangle is entirely inside the circle). Depending on your definition of "collision," you might have to also check if the circle is entirely inside the rectangle!

There are various ways to speed up the computations, in case you are going to invoke this millions of times in a real-time simulation. The most obvious is to first check against the square S circumscribing the circle C, and only then proceed to the (slightly) more costly circle test.