Compute 3D distance between 32 points
10 次查看(过去 30 天)
显示 更早的评论
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.

0 个评论
采纳的回答
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);
0 个评论
更多回答(1 个)
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
2019-1-12
Or, if you have Statistics and Machine Learning Toolbox, pdist2 function will be some help.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!