• Advertisement
Sign in to follow this  

AABB vs AABB Intersection

This topic is 4576 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been googling around for how to do this, but haven't been able to get anything yet. Could anyone explain the procedure, or link me to a site with information on it? Resolving the intersection is not yet needed, I only need to know if there is a collision.

Share this post


Link to post
Share on other sites
Advertisement
project the boxes on X, Y, Z planes.
if the boxes colide, their projected rectangles should overlap on the 3 planes.
now, for early rejections, turn it the other way, if on one plane, the rectangles don't overlap, no need to investigate further, they don't colide.

Share this post


Link to post
Share on other sites
Projecting the boxes on the planes, means doing more work than necessary.

Using the Separate Axes theorem is much easier and faster. (Especially in the case of AABB intersection).

Here's the code:
struct AABB
{
float fMinX, fMaxX;
float fMinY, fMaxY;
float fMinZ, fMaxZ;
};

// Use the Separate Axes theorem to determine if the boxes intersect.
bool isAABBIntersect( const AABB& box1, const AABB& box2 )
{
if ( (box1.fMaxX >= box2.fMinX) && (box2.fMaxX >= box1.fMinX) && // Axis X
(box1.fMaxY >= box2.fMinY) && (box2.fMaxY >= box1.fMinY) && // Axis Y
(box1.fMaxZ >= box2.fMinZ) && (box2.fMaxZ >= box1.fMinZ) ) // Axis Z
return true;

return false;
}

Share this post


Link to post
Share on other sites
of course, DOING the projection on X, Y or Z is stupid because you already have the values you're interested in...
anyway, the idea is the same.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement