我有一個問題想和你分享,以防你能幫助我。我正在處理 3D 線,我需要獲得兩條相交線的最小距離所在的確切點。為什么我需要這些積分?
對于每一條無限長的直線,我只想知道這個最小距離是否與同一條直線上的點的距離在一定范圍內。例如,我有直線 r 的點 P (0,0,0) 和 Q (10,10,10),我只想知道所述最小距離是否在該坐標區間內。
為了獲得距離,我使用以下公式:

但是曾經說過我不知道如何確保在我上面評論的 P 和 Q 值范圍內是否達到這樣的最小距離。

如果有人對如何檢查這一點有更好的想法或知道如何獲得這些積分,我將不勝感激。
uj5u.com熱心網友回復:
如果我理解你的問題:
對于點P獲得兩條線上的正交投影(如果v和w歸一化,則不需要分母)
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
uj5u.com熱心網友回復:
通常,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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/343364.html
