Search code examples
c++collision-detection

2D Polygon Collision Detection


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


Solution

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

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