How to know IF a line segment intersects a triangl

2019-08-15 06:04发布

I have a triangle defined by 3 points in 3d space. I also have a line segment defined by 2 points in 3d space. I want to know if they intersect. I don't really need to know the point of intersection.

I don't know any calculus but I know some trig. I know some about matrices but I understand vectors well (3d vectors specifically). Please keep it simple.

Can you walk me through the example problem:

triangle:

a: -4, 3, 0

b: 4, 3, 0

c: -3, -5, 4

line segment:

d: 1, -2, 0

e: -2, 6, 2

EDIT:

I am going to use this in a c++ physics engine.

One answer involved tetrahedron volume calculation from 4 vertices. Please provide formula or show it in code.

1条回答
干净又极端
2楼-- · 2019-08-15 06:39

Here is one way to solve your problem. Compute the volume of the tetrahedron Td = (a,b,c,d) and Te = (a,b,c,e). If either volume of Td or Te is zero, then one endpoint of the segment de lies on the plane containing triangle (a,b,c). If the volumes of Td and Te have the same sign, then de lies strictly to one side, and there is no intersection. If Td and Te have opposite signs, then de crosses the plane containing (a,b,c).

From there there are several strategies. One is to compute the point p where de crosses that plane. Then project down to 2D, and solve the point-in-triangle problem in 2D.

Another route is to compute the volumes of the tetrahedra (a,b,d,e), (b,c,d,e), and (c,a,d,e). Then only if all three have the same sign, does de intersect the triangle (a,b,c).

How to compute the volume of a tetrahedron from its corner coordinates is all over the web, and also in Computational Geometry in C.

查看更多
登录 后发表回答