Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Calculating amount of overlap/penetration of two 3D AABBs


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Duckymoo   Members   -  Reputation: 105

Like
0Likes
Like

Posted 14 April 2012 - 08:19 AM

Hey folks, I have two 3D AABBs (lets call them boxA and boxB) and I was wondering if there was a way of calculating the amount of overlap/penetration between them in order to resolve interpenetrations. The AABBs are min/max representations although I've added some trivial functions to calculate the "half-widths"/"half-extents" if they are needed.

[If it's helpful to know,] for the contact normal I'm simply using the direction from boxB to boxA (unless one object is the ground, in which case I use the grounds normal). This is possibly incorrect but it is only particle physics being used here so complete 100% accuracy isn't a necessity.

Also, I've read up on the separating axis theorem but I was wondering if this may be slightly overkill for strictly AABBs since it can seemingly be applied to many generic polyhedra.

The only bit of information I need at this time is the overlap/penetration depth.

Here's what I have come up with so far (note: I quite often try to solve the 2D varient first since it'll be easier and then see from that how I can possibly extend it to 3D):

Posted Image

So possibly something along the lines of:
float dx = abs(boxA.min.x - boxB.max.x);
float dy = abs(boxA.min.y - boxB.max.y);
float dz = abs(boxA.min.z - boxB.max.z);
And then possibly the penetration depth is the smallest of these three? (and then the two objects are pushed apart by this distance in the direction of the contact normal although what % of the penetration depth each object moves by is determined by the mass of the objects, heavier objects don't get pushed as far etc).

I'm likely nowhere near correct but it's starting to drive me cuckoo Posted Image

Sponsor:

#2 lawnjelly   Members   -  Reputation: 429

Like
0Likes
Like

Posted 14 April 2012 - 02:38 PM

I'm half asleep (shouldn't post when tired lol) but hopefully this should put you on the right track:

bool Calculate_1DOverlap(float aMin, float aMax, float bMin, float bMax, float &oMin, float &oMax)
{
// providing they DO overlap, then the highest of the 2 minimums must be the minimum of the overlap
// and the lowest of the two maximums must be the overlap max
if (!Test_1DOverlap(aMin, aMax, bMin, bMax)) return false;
if (aMin > bMin)
  oMin = aMin;
else
  oMin = bMin;
if (aMax > bMax)
  oMax = bMax;
else
  oMax = aMax;
return true;
}

Just do a similar routine for each axis (x y and z) and you've got your overlap.

#3 lawnjelly   Members   -  Reputation: 429

Like
0Likes
Like

Posted 14 April 2012 - 02:39 PM

and

bool Test_1DOverlap(float aMin, float aMax, float bMin, float bMax)
{
if (aMin >= bMax) return false;
if (bMin >= aMax) return false;
return true;
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS