# Collision between a cube and a triangle.

This topic is 4428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I got an airplane and a terrain I want to check collision between. I've considerd to make a bounding box around the plane and check collision between the bounding box and the terrain. I dont load in the terrain from a bitmap but from a mesh and I then organize the triangles in a array. I thought to check all the triangles in my bounding box against the triangles in the terrain the plane is hovering over. So far so good, But what is the fastest equation for doin an intersecton?, and is there possibly an even more optimized way to check a box against a triangle?. Thanks in advance!.

##### Share on other sites
Unless you need greater accuracy, I would use a sphere, as it will be quite a bit easier. A discrete sphere-triangle test requires only a point-to-triangle closest-point test, which you should be able to find online (or ask here if you can't find it). From there you can determine a boolean result, plus penetration depth and direction if needed.

Other options might be ellipsoids or capsules. If you want to use an AABB or OBB, you'll most likely want to use the separating axis theorem, which is a bit more complicated to implement.

##### Share on other sites

I checked some functions on google but the only thing I found was intersection between triangles and a point ray. I would be very thankfull if you could link me to a site that describes the sphere to triangle intersection or even better if you have the time to give me a code example :-) (I prefer C#). I havnt got into very advanced math yet (due to my age) so I would be gratefull if it was written in an 'easy' language. Thanks in advance, Frisker

##### Share on other sites
When I just need an intersection test, I typically go to Dave Eberly's web site Geometric Tools. I also recommend picking up one of his books; his Wild Magic library (that comes with the books) is sometimes a useful source of various code.

Once you know how to collide a sphere with a triangle, you will realize that testing 1,000,000 triangles each frame is fairly inefficient, and you'll want to put your triangles into some sort of spatial hierarchy (octree, quadtree, etc). At that point, you could do worse than reading Christer Ericson's book on Real-Time Collision Detection; it's fairly thorough.

##### Share on other sites
Well, I have already divided all the triangles into an array (it's called space divison right?). I downloaded the pdf Distance Point - Triangle from your geometry site. To be honest I didn't know about 50% of the mysterious signs he used in his calculations. Should I put down game programmering until my math skill has been increased? :-(

##### Share on other sites
Quote:
 Original post by FriskerWell, I have already divided all the triangles into an array (it's called space divison right?). I downloaded the pdf Distance Point - Triangle from your geometry site. To be honest I didn't know about 50% of the mysterious signs he used in his calculations. Should I put down game programmering until my math skill has been increased? :-(
Hehe, don't be discouraged by Dave's materials. They're great references, but are also quite dense, mathematically speaking. If you get stuck on something you can always post here and ask for help.

As for the point-triangle closest-point test, it's based on some (relatively) simple calculus and linear algebra (specifically constrained minimization of a quadratic equation). There are other ways to formulate the problem as well that might be somewhat more intuitive.

##### Share on other sites
Thanks for the answer!. So I wonder if anyone here could explain the point-to-triangle distance equation here with quite simple mathematics?. I've studied linear equations so I suppose it wont be any problems :-) (Or should I make a new post about the matter?).

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5

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

• Total Topics
633655
• Total Posts
3013187
×