Compute 3D distance between 32 points

10 ビュー (過去 30 日間)
Mihai Rares Sandu
Mihai Rares Sandu 2019 年 1 月 11 日
回答済み: Image Analyst 2019 年 1 月 12 日
I have encountered the following problem: I have to divide a square with L=12 in 4x4 smallers squares and find the center point of each small square. This will represent surface 1 and then i have to do the exact thing for surface 2.
Now, i have to compute the distances between each center of surface 1 and each center of the surface 2. So i will have a total of 256 distances. How do i do that ? Check out the photos.

採用された回答

Image Analyst
Image Analyst 2019 年 1 月 12 日
To find the distance from every one of 16 points to every one of another set of 16 points would give 16 * 16 = 256 distances. You can get these out in a 16 by 16 2-D array using pdist2(). Attach your data (2 lists of points) in a .mat file if you need more help.
distances = pdist2(xySet1, xySet2);

その他の回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 1 月 11 日
The distance beween two points, p1 and p2, in 3d space is the square root of (x2 - x1)^2 + (y2-y1)^2 + (z2-z1)^2.
So let's have 2 matrices representing the centerpoints in surface 1 and two:
s1 = [p1x p1y p1z
p2x p2y p2z
p3x p3y p3z];
s2 = [p1x p1y p1z
p2x p2y p2z
p3x p3y p3z];
Where each column represents the x,y, and z components of a point. Then just sum the squares of the differences and take the square root
d= s2-s1;
sq = d.^2;
distance = sqrt(sum(sq,2)) % sum up along the row elements
You should be returned with a vector containing the distances between each pair of points from the two surfaces
  2 件のコメント
Akira Agata
Akira Agata 2019 年 1 月 12 日
Or, if you have Statistics and Machine Learning Toolbox, pdist2 function will be some help.
Mihai Rares Sandu
Mihai Rares Sandu 2019 年 1 月 12 日
Thank you for answering !
I tried your method but the result will be a vector of 4 elements and the total number of elements shoud be 256 because on surface 1 i have 16 center points and on surface 2 i have other 16 center points. I have to compute the distance between each center point. So for center point 1 surface 1 to center point 1:n of surface 2.
It will be 16 distances between center point 1 of surface 1 and all the center points of surface 2. Then there are 15 other center points for surface 1.
I hope i explained well.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by