[Math] How to find the Intersection of two 3D triangles

3dcollision detectiongeometrytriangles

I've got a rather complicated geometry problem that I'm trying to solve – how to find the intersection between two triangles in 3D space. I've looked around at other questions and answers on this site and quite a few others, but none of them seem to satisfy my question.

Anyway, given two triangles on two intersecting planes, and a line of intersection (a vector V), how would I be able to tell if any part of the intersection line is contained in both triangles?

Intersecting triangles

So far I've been able to, given two triangles, find their two planes, and the direction vector of the line where they intersect. I think I might be able to find if the line of intersection is contained in one triangle by projecting to 2D, but I'm not sure how to find if that line of intersection is contained in both triangles.

As far as I can tell, there's not much documentation on triangle to triangle collision, if anybody could tell me the step by step process to find the line of intersection between the triangles (and/or if it exists) rather than the line of intersection between the two planes, that would be great.

Btw I'm not quite looking for a "conceptual" solution (there's plenty of that out there already) but I'm wondering if anybody could enlighten me on the actual math for such an intersection test. Thanks!

EDIT:
Here's an example problem – if you would be so kind as to show me a step by step solution of the problem, then thank you very much! 🙂

Example problem

Btw when I say "find the line of intersection between them", I mean a line segment. (sorry for the typo)

Best Answer

Here's one way to do it:

Step 1: Determine the planes determined by the two triangles.

Step 2a: If they are the same plane, this has become a two dimensional problem.

Step 2b: If the planes are different there are many options.

Step 3: The vertices of triangle 1 cannot all be on the same side of the plane determined by triangle 2. Similarly, the vertices of triangle 2 cannot be on the same side of the plane determined by triangle 1. If either of these happen, the triangles do not intersect.

Step 4: Consider the line of intersection of the two planes. This line intersects both triangles by step 3. Now, compute the intersection (a two dimensional problem, the intersection is a segment determined by the intersection of the intersection of the line with the lines determined by the edges of the triangles.

Step 5: Determine if the segments (which are on the same line) intersect.