Calculate Euclidean Distance between one point and many others

6 Ansichten (letzte 30 Tage)
Iliqe
Iliqe am 6 Mär. 2022
Beantwortet: Matt J am 6 Mär. 2022
The idea is to calculate the Euclidean distance from certain point to many other points, e.g., we have point with coordiantes 0 0 0 along X, Y, and Z. And we have 10 other points with any coordinates. And the output is vector with 10 distances from our point 0 0 0 to other points.
Is there an efficient way to do it? I wrote my own simple fucntion which calculate the Euclidean distance in a loop. But I have millions of calculataions. And it would be great to have smth fast.

Akzeptierte Antwort

Matt J
Matt J am 6 Mär. 2022
xyz=rand(3,10); %points
Dist=vecnorm(xyz,2,1)
Dist = 1×10
1.2806 0.8949 0.8368 1.1284 0.8050 1.1707 1.3917 1.3063 0.9286 1.0914

Weitere Antworten (1)

Torsten
Torsten am 6 Mär. 2022
Dist = sqrt(X.^2 + Y.^2 + Z.^2)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by