Compute 3D distance between 32 points
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mihai Rares Sandu
el 11 de En. de 2019
Respondida: Image Analyst
el 12 de En. de 2019
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 comentarios
Respuesta aceptada
Image Analyst
el 12 de En. de 2019
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 comentarios
Más respuestas (1)
Kevin Phung
el 11 de En. de 2019
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 comentarios
Akira Agata
el 12 de En. de 2019
Or, if you have Statistics and Machine Learning Toolbox, pdist2 function will be some help.
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!