segment intersecting a tetrahedron

时间:2015-09-01 22:08:05

标签: algorithm computational-geometry

I am trying to write C++ code to find the intersection points of a segment intersecting a tetrahedron. I reduced the problem like this:

  1. For each face of the tetrahedron (a triangle), find the intersection point of the line segment. Then, I have three cases: a) The segment doesn't intersect any face - thus either the segment is entirely in the tetrahedron or completely outside. b) The segment only intersects one face. Then I just need to determine the side of the segment that is in the tetrahedron and I get the two points that are in the tetrahedron. c) The segment intersects two faces.

I am having trouble implementing this algorithm. Here are the issues:

  1. If the segment and triangle are in the same plane, how do I find the intersection points?
  2. How can I determine if the segment lies on one of the edges of the tetrahedron?

Thanks.

3 个答案:

答案 0 :(得分:0)

<强>提示

您无法避免复杂的案例讨论。这里我介绍一个线段和三角形的平面情况。

三角形的边界定了三条直线,这些直线在7个区域划分平面,一个是有界的,另一个是无界的。在图中,它们是通过在这些线的三个隐式方程中插入一个点的坐标时获得的符号来指定的。

如果您需要精确考虑端点,则需要在讨论中添加6个半行和3个段。

然后采用起始区域和结束区域的所有可能组合。

许多案件都很简单。当两个分段端点属于同一区域时,该分段完全在内部或外部;当其中一个区域为+++而另一个区域不同时,只有一个交叉点......

如果是图(--+++-),你肯定会有一个与底边相交的地方;但是另一个相交的方面是不确定的:要回答这个问题,你需要告诉顶部顶点位于线段的哪一侧。

enter image description here

有了一些勇气,你可以讨论所有16 x 15 / 2 = 120个案例,其中许多案例与元素的排列相同。

与3D问题相比,这只是一种开胃菜。

答案 1 :(得分:0)

  

“我怎样才能确定该段是否位于四面体的一个边缘上?”

编写一个函数,计算由空间中的三个点确定的三角形区域。这可以从决定因素计算,如here和许多其他网站所解释的那样。

然后编写一个函数,确定两个段ab和cd是否共线。 当且仅当abc的面积为零,并且abd的面积为零时才是它们。

最后,编写一个函数,确定一个点c是否位于段ab上。有了这一切,剩下的就很容易了。

答案 2 :(得分:0)

为了回答一般性问题,即如何找到一个段和一个四面体之间的(最多两个)交叉点,我宁愿避免痛苦的逐案分析(在你的问题减少和另一个问题中提到)回答)。

我会使用Sutherland-Hogdman的折返剪辑的变体(在[1]中的2D中解释):想法是将四面体视为四个定向半空间之间的交点(受四个面的支撑平面限制) (四面体)。

因此,要计算段和四面体之间的交集,可以按以下步骤操作:

S := your segment
for f := 0 to 3 {
   H := half_space(tet, f)
   S := intersect(S, H)
}

H只是一个平面方程(方程ax +的系数a,b,c,d + + cz + d = 0, [a,b,c]是小平面的法线,朝向四面体的内部。通过将入射到顶面的顶点注入等式中来获得d)。

函数intersect()很容易实现(只需在段的两个顶点测试ax + by + cz + d的符号,如果它们不同,就有一个交点,可以通过注入参数方程来计算S x = x1 + t(x2-x1),y = y1 + t(y2-y1),z = z1 + t(z2-z1)成(ax + by + cz + d = 0)并求解t,其中(x1,y1,z1)和(x2,y2,z2)表示S的两个极端。

此外,函数intersect()可以计算两个布尔值,以跟踪S的哪个顶点是生成的交集。

[1] https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm