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?

 채택된 답변

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)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

2013년 5월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by