Compute 3D distance between 32 points
조회 수: 15 (최근 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!