简体   繁体   English

检查3D空间中两条线段是否相交

[英]Check if if two line segments intersect in 3D space

I'm trying to find if two line segments intersects in 3D space.我试图找出两条线段是否在 3D 空间中相交。 Both segments are given by points (x1, y1, z1) and (x2, y2, z2).两个段都由点 (x1, y1, z1) 和 (x2, y2, z2) 给出。 The following artcile describes how to do it in 2D space: https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/ but I have no clue how to distinguish points orientation in 3D space (if they are clockwise or counter-clockwise).以下文章描述了如何在 2D 空间中执行此操作: https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/但我不知道如何区分 3D 空间中的点方向(如果它们是顺时针或逆时针)。 Thanks in advance.提前致谢。

Calculate direction vectors d1 and d2 for both segments ( d1.x = x12-x11 and so on, where x11 is starting point of the first segment, x12 is ending point)计算两个段的方向向量d1d2d1.x = x12-x11等等,其中x11是第一段的起点, x12是终点)

Calculate starting points difference ( bx = x21 - x11 and so on)计算起点差( bx = x21 - x11等等)

Find寻找

p = (d1 x d2) (vector product)

If p is zero vector, then lines are parallel.如果 p 是零向量,则线是平行的。

If lines do intersect, (b.dot.p) should be = 0 (scalar product), else these lines are skew.如果线条确实相交,则(b.dot.p)应该 = 0(标量积),否则这些线条是倾斜的。

Intersection point:交点:

ip = point11 + d1 * [ (b x d2).dot.p / (p.dot.p) ]

Note that value in [] should be in range 0..1 , otherwise lines intersect outside of segments.请注意, []中的值应在0..1范围内,否则线在线段之外相交。

Seems similar approach is described in wiki似乎在wiki中描述了类似的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM