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

5 visualizaciones (últimos 30 días)
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 comentario
Noella Makhlouta
Noella Makhlouta el 5 de Dic. de 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},

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 5 de Dic. de 2018
Editada: Bruno Luong el 5 de Dic. de 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)

Más respuestas (1)

Torsten
Torsten el 5 de Dic. de 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))

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by