how to find the shortest distance between two lines in R3 ?

5 ビュー (過去 30 日間)
Noella Makhlouta
Noella Makhlouta 2018 年 12 月 5 日
コメント済み: Noella Makhlouta 2018 年 12 月 6 日
I need to find the shortest distance between two lines in R3, and I have the point (x,y,z)=(0,0,0)
I know how to plot the lines on a graph, after that I get stuck..
Thanks in advance
  1 件のコメント
Noella Makhlouta
Noella Makhlouta 2018 年 12 月 5 日
L1 = {(x,y,z) ∈ R 3 | x = 10 + 3t, y = −1 + 2t, z = −1.5 − 0.01t, t ∈ R},
L2 = {(x,y,z) ∈ R 3 | x = −1 − 0.1t, y = 2t, z = −2.5 + 0.02t, t ∈ R},

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2018 年 12 月 5 日
編集済み: Bruno Luong 2018 年 12 月 5 日
No need a big hammer, a simple formula is enough
d = abs(null([x1(:)-x0(:),y1(:)-y0(:)]')'*(x1(:)-y1(:)))
Or to avoid NULL
n = cross(x1(:)-x0(:),y1(:)-y0(:));
d = abs(n'*(x1(:)-y1(:)))/sqrt(n'*n)

その他の回答 (1 件)

Torsten
Torsten 2018 年 12 月 5 日
% Line 1 is given as x=x0+lambda*(x1-x0)
x0 = ...;
x1 = ...;
% Line 2 is given as y=y0+eta*(y1-y0)
y0 = ...;
y1 = ...;
fun = @(x) sum(((x0+x(1)*(x1-x0))-(y0+x(2)*(y1-y0))).^2);
xstart = [0 0];
sol = fminsearch(fun,xstart);
distance = sqrt(fun(sol))

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by