如何确定空间中两条不相交直线之间距离的点

4
我有一个问题想要和您分享,希望您能帮助我。我正在处理3D线条,并且需要获取两条交叉线的最小距离所在的精确点。为什么我需要这些点呢?
对于每一条无限长的直线,我只关心该最小距离是否在同一条直线上某些点的特定范围内。例如,我有一条线r,它的点是P(0,0,0)和Q(10,10,10),我只关心所述最小距离是否在该坐标区间内。
为了得到距离,我使用公式:
但是,我不知道如何确保上述P和Q的值范围内达到了这种最小距离。
如果有人有更好的想法来检查这一点或者知道如何获得这些点,我会非常感激。

请展示一个带有 PQ 的图表。第二条线是如何参数化的?如果这两条线相交,那么它们之间的最小距离为0。检查交点是否在点 PQ 之间非常简单。您确定这两条线是相交的吗? - Mad Physicist
一些链接:https://math.stackexchange.com/search?q=minimum+3d+distance+lines,特别是[这个问答](https://math.stackexchange.com/questions/1993953/closest-points-between-two-lines)或[这个维基百科](https://en.wikipedia.org/wiki/Skew_lines#Nearest_Points)。 - Ripi2
线段不相交,但是它们相交。因此我没有交点。 - Carles Sastre Pérez
你在帖子中写的公式并不是一对斜线(即不相交且不平行的三维线)之间最短距离的公式。你所写的是三维空间中点到直线的最短距离公式。 - Futurologist
2个回答

0
如果我理解你的问题正确:
对于点 P,在两条直线上分别获得正交投影(如果 vw 已经被标准化,则不需要分母)
PAproj = A - P + dot(AP, v) / dot(v,v) * v
PBproj = B - P + dot(BP, w) / dot(w,w) * w

然后检查这些向量是否是反共线的

 cross(PAproj, PBproj) == 0   
   and 
 dot(PAproj, PBproj) has negative sign

0
通常情况下,3D中的线条是由线上一个点的坐标和与该线对齐(或平行)的一个向量的坐标来指定的。因此,我假设您输入的数据是:
1) line s with point S = [xS, yS, zS] on l and a vector u = [u1, u2, u3] aligned with s

2) line r defined by the pair of points P = [xP, yP, zP] and Q = [xQ, yQ, zQ] 

Your goal is to check whether the point on r that is closest to line s 
is inside the line segment PQ on r or not.

算法。

n = u x (Q - P)
SP = P - S
SQ = Q - S
proj_SP = SP - ( (n . SP) / (n . n) )  n 
proj_SQ = SQ - ( (n . SQ) / (n . n) )  n
w = n x u
if (proj_SP . w) * (proj_SQ . w) < 0
    then the point on r that is closest to line s 
         is inside the line segment PQ
else
         the point on r that is closest to line s 
         is outside the line segment PQ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接