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?

 採用された回答

José-Luis
José-Luis 2013 年 5 月 23 日
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 ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2013 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by