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

5 visualizzazioni (ultimi 30 giorni)
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 Commento
Noella Makhlouta
Noella Makhlouta il 5 Dic 2018
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},

Accedi per commentare.

Risposta accettata

Bruno Luong
Bruno Luong il 5 Dic 2018
Modificato: Bruno Luong il 5 Dic 2018
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)

Più risposte (1)

Torsten
Torsten il 5 Dic 2018
% 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))

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by