Jump to content
• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# AABB collision %???

This topic is 5850 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

Howdy. I was wondering if anyone had some pointers for the following problem. I have 2 AABB''s, One quite large (Box A), and one quite small (Box B). I would like to compute "how much" of box B is inside of Box A. If it''s > 50% then i would like to do "stuff" to it. Can anyone help with the calculation of how "much" box B is inside box A? ~Main == Colt "MainRoach" McAnlis Programmer www.badheat.com/sinewave

#### Share this post

##### Share on other sites
Advertisement
clip boxB by boxA, then calculate volumen B_Cliped,volumen boxB, and you got the difference

#### Share this post

##### Share on other sites
I apologize for my lack of math background, but could you explain it in a bit more detail?

~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave

#### Share this post

##### Share on other sites
to some extent you may be able to just cheat/lie a little and just say that when the center of the smaller box is inside the larger box then do stuff. or say something like do stuff when 2 vertices + the center are inside. i think that guarantees you at least a 25% case. i don''t really know what you are doing or how accurate you need to be so i''m not sure that''s necessarily useful.

-me

#### Share this post

##### Share on other sites

(Trying again as first posting attempt failed.)

You do this:

struct AABB {
float min[3]; // minimum value along x/y/z-axis
float max[3]; // maximum value along x/y/z-axis
};

// Computes volume of an AABB
float Volume(AABB &v) {
return (v.max[0]-v.min[0]) *
(v.max[1]-v.min[1]) *
(v.max[2]-v.min[2]);
}

// Your two AABBs
AABB a, b;

// Computer intersection c of a and b
AABB c;
for (int i = 0; i < 3; i++) {
c.min = Max(a.min[i], b.min[i]);
c.max[i] = Min(a.max[i], b.max[i]);
}

// Compute ''fractionInside'' indicating how much
// of the volume of the smaller AABB lies inside
// the larger AABB (in the range [0, 1])
float smallerVolume = Min(Volume(a), Volume(b));
float fractionInside = Volume(c) / smallerVolume;

Now you test:

if (fractionInside > 0.5f) ...do whatever...

Christer Ericson
Sony Computer Entertainment, Santa Monica

#### Share this post

##### Share on other sites
Ahh! Thank you indeed!
~Main

#### Share this post

##### Share on other sites

• Advertisement

### Announcements

• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12
• Advertisement

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!