Archived

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

outRider

triangles in a cube vol

Recommended Posts

I''m trying to figure out how to test for triangles inside a bounding cube, and I really can''t figure it out. I''d appreciate any helpful hints someone has.

Share this post


Link to post
Share on other sites
I interpret your messages meaning to "test if a triangle is inside a bounding box" right ?
Im not a l33t programmer, but i am a math GOD hehe :b ..anyways there may be special functions to do this that is faster, i dunno about that but here goes:

if the cube beeing "bounding" mean that the sides in it are parallell to the x/y/z axis then its easy.. first find the x coordinates of the two sides facing along the x axis ( ie the sides of which the normal vector would be paralell to the x axis ) and decide which of them has the highest x value.. then, if any of the x coordinates of the triangle ( there should be three sets of x/y/z values if it is a triangle )is greater than the greatest x value of the cube or if any of them are smaller than the smallest x value of the cube then you know for certain that the triangle ( or parts of it ) is outside the cube. If all the x values of the triangle is within the range of the cubes "x-sides" then u have to do the same with the y values ( and offcourse use the sides in the cube facing along the y axis ) and if all of those too is inside, then test the z coordinates.. and if they all turn out to be inside then u know that all of the triangle is inside the cube.

If the cube is not parallell to the x/y/z axis.. (or if the sides is not paralell to eachother) ..then its complicated. You have to find the plane formula for the sides, and to do that you must first find the normal vectors (using the cross-product ( or X-product (don''t confuse the X with the x-coordinate))).. if you want me to explain this more throughoutly just ask ;-)

ok.. did that help, or was it just confusing lol ?

Share this post


Link to post
Share on other sites
I've had my fair share of math so I know how to find a plane formula and how to test for line/point/plane intersection, but I hadn't thought of volumes. What I was thinking before posting this was that if you imagine you're working with a 2D square for example, instead of a bounding box, you can see if a point is within the square by checking to see if the point's x component is between the square's near x intercept and the far x intercept, and then check the y component, I'm guessing that for a 3D bounding box, or cube I guess is the corrent term I'd just add a check for the z component. I thought maybe there was a quicker way to do it, but this isn't so bad, the bounding box is orthogonal so it's no big deal. Thanks for the help.

Edited by - outRider on June 24, 2001 9:29:37 PM

Share this post


Link to post
Share on other sites