I have two object-aligned bounding boxes (i.e. not axis aligned, they rotate with the object). I'd like to know if two object-aligned boxes overlap. (Edit: note - I'm using an axis-aligned bounding box test to quickly discard distant objects, so it doesn't matter if the quad routine is a little slower.)

My boxes are stored as four x,y points. I've searched around for answers, but I can't make sense of the variable names and algorithms in examples to apply them to my particular case.

Can someone help show me how this would be done, in a clear and simple way? Thanks. (The particular language isn't important, C-style pseudo code is OK.)


If you know where to look it is easy. You are looking for oobb. Go here: http://www.realtimerendering.com/intersections.html.
There you find link to this site http://www.geometrictools.com/LibMathematics/Intersection/Intersection.html
and there find correct code. (ctrl+f "Intersection of boxes (2D)")

It uses SAT and contains source codes and article.

| improve this answer | |
  • \$\begingroup\$ The algorithm described by the geometrictools is the one I would have pointed at. \$\endgroup\$ – Jari Komppa Jan 31 '11 at 13:15
  • \$\begingroup\$ I get that this was 4 years ago, but always explain a downvote and all that. This is pretty "Your answer is in another castle", and now the answer doesn't even seem to be there in the second case. \$\endgroup\$ – Yann Nov 26 '15 at 21:54

The easier way is probably to test each vertex of box B against each side of box A (compute the signed distance). This way you can classify each vertex as "in front" or "behind" the segment.

If all of B's vertexes classify as "in front" of one of A's segments, B and A don't overlap; otherwise, they do.

This is somewhat involved, so you may get some performance gain by doing a circle-circle check first, using the bounding circles of the squares (trivial to compute)

| improve this answer | |
  • \$\begingroup\$ I'm first doing an axis-aligned bounding box test to quickly discard distant objects... do you have any more details on the quad-quad test though? \$\endgroup\$ – AshleysBrain Jan 30 '11 at 22:19
  • \$\begingroup\$ temporarily rotate both quads with the same transform such that one of them ends up axis aligned... then use the SAT test as notabebe mentioned. when result is found, inverse the rotation to get them back. \$\endgroup\$ – Steve H Jan 31 '11 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.