# Find if two triangles intersect in 3D environment

1. Apr 11, 2015

### NotASmurf

Hey all, I need to know when two triangles intersect in a 3D environment, given the 3 points. Any help apreciate have been stuck on this for a long time,

2. Apr 11, 2015

### mathman

It is a tedious process.
Step one. Get the equations of the planes containing the triangles.
Step two. Compute the line of intersection of these planes.
Step three. Find the points of intersection of this line with each of these triangles. If either miss you are done, since the triangles can't overlap.
Step four. These intersection points define a pair of intervals (one for each triangle). If the intervals overlap, the triangles overlap along this overlap interval. Otherwise they do not overlap.

3. Apr 12, 2015

### NotASmurf

How does one do that? I know gettign the cross product of the normals will get the direction but How would one find a point on both? if theres an algorithmic way that woudl be great as this is for a program im writing.

4. Apr 12, 2015

### mathman

Take the two equations for the planes. Arbitrarily set one coordinate to 0. Now you have 2 equations in 2 unknown coordinates. Solving will give you the other 2 coordinates for that point.

5. Apr 12, 2015

### beer

Are you given three points per each triangle? ie six points total?

Also are you finding IF they intersect or WHERE they intersect?

You know that the triangles exist on specific planes, and that planes stretch to infinity. One way to determine if the triangles DO NOT intersect is to determine if the normal vectors of each triangle-plane are parallel. If the normal vectors are not parallel, then the triangles might intersect. At which point, you need to determine if the lines/vectors formed by the sides of any triangle intersect the area of the other triangle.

For coding purposes/idiot proofing a special circumstance you might want to keep in mind is if the distance between the planes and or triangles is zero... which means you're analyzing the same area.

6. Apr 13, 2015

### mathman

If you intend to write a computer code, you must take care of special cases. The planes may be parallel. The line of intersection may be constant in one or two coordinates.