# How do you implement 2D collision detection?

I would like to know the best or most efficient way to test for 2D collision.

I am currently using AABBs, but the problem with this, is that your objects will be hitting things when they shouldn't. On top of this, AABBs cannot be rotated.

I was considering using per pixel collision, but I feel that it would lag on large bitmaps, since there would be a lot of pixels to check.

What I would like to know, is how I can allow my bounding boxes to be rotated, and use any polygon instead of just rectangles for collision. Also, is there a way of creating circular collision bounds that aren't just approximations of circles?

• Why would you use atan2() for circle vs. circle? – bummzack Feb 20 '12 at 10:18
• For circle circle collision, all that you have to do is check whether the distance between the centers is less than the sum of the radiuses. Also, avoid atan2() if you can - the function is incredibly slow. – mdkess Feb 20 '12 at 15:23