Jump to content
• Advertisement

# Volume of two intersected boxes.

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

Hi all! I need to calculate the volume of two intersection OBB's (wich is the same as the intersection of one AABB and one OBB). Is there a simpler method than intersecting them using CSG at polygon level and then calculate the remaining volume? I could live with an approximation of some sort, I'd just like to get an ratio of how much of box A is inside box B. Maybe I could distribute points on a grid inside A and then calculate the number of points inside B. I.e: insideRatio = pointsInsideB / totalPoints; Any hints suggestions are welcome.

#### Share this post

##### Share on other sites
Advertisement
A very crude approximation could be to use the separating axis theorem to compute an approximate penetration depth, and use the ratio of this to the extents of the box. If you test all potential separating axes and the objects are intersecting, the axis with the smallest overlap gives an approximate collision normal and the overlap is an approximation of the penetration depth. This would probably be quite fast to compute but would be quite inaccurate in some cases :)

#### Share this post

##### Share on other sites
Yeah, I was thinking about using the penetration depth as an approximation.
Haven't gotten around to try it out yet though.
The approximation using sample points works but is very slow since I need around 200-300 points for each test to get a good approximation (and there's quite a few tests in my application).

I still think that a full blown CSG version would be faster but there's to much code in there...

#### Share this post

##### Share on other sites
On a second thought there isn't to much code involved to create the intersected volume since both the AABB, OBB and intersection is convex:

Intersection = OBBFor each plane in AABB   For each polygon in Intersection      Clip polygon agains plane and add each new edge to list of open edges   End   If list of open edges is empty continue with next plane (i.e no clipping against plane was done)   Add a new polygon to Intersection from the list of open edgesEnd

Does the above work?
If so how does one find the volume of a convex mesh as produced above?

#### Share this post

##### Share on other sites
I keep on answering my self :)
The volume of a convex mesh should be the sum of the volume of all terahedrons formed by the center vertex and all triangles on the mesh surface, right?

#### Share this post

##### Share on other sites
Yep you've answered yourself pretty well :) Clipping one convex polyhedron by the planes of the faces of the other will generate a convex polyhedron as you've said, and yes the volume is given by the sum of the volumes of the tetrahedra formed by the centroid and each triangle in the mesh.

#### Share this post

##### Share on other sites
Implemented the clipping method and it seems to work ok.
I've only tested it by rotating the boxes around one axis and project them in 2d so far but all calculations is done fully in 3d.

Edit: The bounding values of the projection axis are -1 and 1 for both boxes, so they are fully overlapping there.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5
• Advertisement

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631768
• Total Posts
3002242
×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!