Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.)

share|improve this question

2 Answers 2

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.

share|improve this answer
    
The algorithm described by the geometrictools is the one I would have pointed at. –  Jari Komppa Jan 31 '11 at 13:15

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)

share|improve this answer
    
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? –  AshleysBrain Jan 30 '11 at 22:19
    
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. –  Steve H Jan 31 '11 at 2:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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