2D Polygon Collision Detection

Matt picture Matt · Oct 19, 2010 · Viewed 20.1k times · Source

Does anyone know a simple way to check if two polygons, especially rectangles, are colliding? I found a simple way to see if two are touching by just checking if any lines on the two rectangles are colliding, but this will not work if one polygon is in another. Does anyone know a more efficient way to do this or just a way that works?

Also, can someone please give me a formula for it or something like that and not just your thoughts on the subject.

Thanks

Answer

GManNickG picture GManNickG · Oct 19, 2010

Look up the Separating Axis Theorem. There's a tutorial here.

It's quick, elegant, robust, not too hard, and has lots of resources.