How can I calculate distance between a point and a line in 4D (or space higer than 3D)?

Is there a function in MATLAB that calculates the shortest distance from a point to a line in N-Dimentional space?

 Réponse acceptée

No, there's not, but you can calculate it using the dot product and the norm for any number of dimensions:
numDim = 4;
A = rand(numDim,1); %Point in line
B = rand(numDim,1); %Point in line
P = rand(numDim,1); %Point outside line
pa = P - A;
ba = B - A;
t = dot(pa, ba)/dot(ba, ba);
your_dist = norm(pa - t * ba,2)

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by