What's a good way to test if a triangle intersects an axis aligned bounding box in 3D?
Currently I test if the AABB around the triangle intersects the other AABB, but clearly that solution will generate some false positives.
Thanks!

**0**

# triangle - AABB intersection

Started by Lode, Apr 08 2006 10:52 PM

7 replies to this topic

Sponsor:

###
#4
Members - Reputation: **982**

Posted 09 April 2006 - 03:07 AM

Quote:

Original post by BlackSheep

OTTOMH - Simply checking each vertex of the triangle is inside the AABB will do it. Quite a lot of point-plane distance tests though. Maybe there's a cleverer way than just brute-forcing it.

Sometimes all vertices of the triangle are outside the AABB, and still a part of the triangle may go through the AABB, I'd like to include those cases too.

###
#5
Members - Reputation: **100**

Posted 09 April 2006 - 03:52 AM

Quote:

Original post by LodeQuote:

Original post by BlackSheep

OTTOMH - Simply checking each vertex of the triangle is inside the AABB will do it. Quite a lot of point-plane distance tests though. Maybe there's a cleverer way than just brute-forcing it.

Sometimes all vertices of the triangle are outside the AABB, and still a part of the triangle may go through the AABB, I'd like to include those cases too.

If you use the hyperplanes of the AABB rather than the absolute rectangular boundaries, you'll catch those too.

###
#7
Members - Reputation: **982**

Posted 09 April 2006 - 09:03 AM

The separating axis test sounds interesting. However, I don't know how it works, and a google search doesn't return any in depth explanation or tutorial. I found an old gamedev.net post about the box triangle test involving 13 axes, but I don't know what it means.

How to perform a separating axis test?

Thanks!

How to perform a separating axis test?

Thanks!

###
#8
Members - Reputation: **1977**

Posted 09 April 2006 - 09:20 AM

Quote:You're right, this particular test doesn't seem to be documented so much online. Here's some code which might do the trick; I didn't look at it carefully though, so I'm not sure what method is employed.

Original post by Lode

The separating axis test sounds interesting. However, I don't know how it works, and a google search doesn't return any in depth explanation or tutorial. I found an old gamedev.net post about the box triangle test involving 13 axes, but I don't know what it means.

How to perform a separating axis test?

Thanks!

The SAT itself is well-documented, and once you understand it thoroughly, applying it to different object pairs is fairly trivial. With AABB vs. triangle, the axes to test are:

- 3 AABB axes, which are the global axes

- 1 triangle normal

- 9 cross products, between each edge of the triangle and the three global axes

For a total of 13. A lot of this can of course be nicely optimized due to the axis alignment (watch out for degenerate cross products though).