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

5 vues (au cours des 30 derniers jours)
Noella Makhlouta
Noella Makhlouta le 5 Déc 2018
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 commentaire
Noella Makhlouta
Noella Makhlouta le 5 Déc 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},

Connectez-vous pour commenter.

Réponse acceptée

Bruno Luong
Bruno Luong le 5 Déc 2018
Modifié(e) : Bruno Luong le 5 Déc 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)

Plus de réponses (1)

Torsten
Torsten le 5 Déc 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))

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by