Azzera filtri
Azzera filtri

From 3D points to 2D matrices

5 visualizzazioni (ultimi 30 giorni)
Julia
Julia il 8 Dic 2016
Hi everyone, I have a very straight-forward question, but I seem to have lots of difficulty to find a clear response online (I read through at least 10 posts on Mathworks and stackoverflow, and can't find a clear answer).
I basically want to convert a cloud of points (matrix Nx3) into three 2D matrixes representing the planes X-Y, Y-Z, X-Z.
Basically if I was to give you a cloud of points generating a sphere:
r=1;
p=1;
for phi=0:0.1:pi
for theta=0:0.1:2*pi
X(p)=r*cos(theta)*sin(phi);
Y(p)=r*sin(theta)*sin(phi);
Z(p)=r*sin(phi);
p=p+1;
end
end
You could view it as a cloud of points with scatter:
scatter(X,Y,Z);
Now I want to transform that data to three 2D matrixes (xy, yz, xz), such that I could plot them with surf:
surf(xy,yz,xz);
I know I could get these three matrices with that function:
[xy yz xz]=sphere(n);
But I basically would like to do that for 3D data (not analytical functions). The sphere is just a particular example :)
How can I do that? so it looks like I need to do an interpolation of the projection of these points on the three normal planes.
Thanks a lot for your help!

Risposte (1)

Walter Roberson
Walter Roberson il 8 Dic 2016
In a situation such as that, you would generally end up with several values in the z plane for some x, y combinations. In order to surf() you need to decide which of the several values will be your "representative" values. You could choose mean() or median(), but for your purpose you probably instead want either min() or max() depending on the angle of view.
  2 Commenti
Julia
Julia il 8 Dic 2016
Modificato: Walter Roberson il 8 Dic 2016
Hello!
Thanks a lot for the quick answer.
I didn't think of that actually...
So the reason why I am trying to do this is because I want to estimate the principle curvatures at all the points of a 3D shape using the surfature function, which accepts as parameters three 2D planes: https://www.mathworks.com/matlabcentral/fileexchange/11168-surface-curvature
The problem is that the data I am importing is made of Nx3 vertices and Nx3 faces (from a STL file).
I thought the best way to use the function, would have been to take the vertices and somehow convert them to three 2D matrices (hence my question), which I could then send to the surfature function.
But after your answer, I am realizing, that not be the best way...
Do you have any recommendations?
Thanks again!
Walter Roberson
Walter Roberson il 8 Dic 2016
I suggest that you quantize the permitted range of values in each direction, and then convert each 3D coordinate into the corresponding indices. That is, if you were to divide the space up into a 3D grid of cuboids, then for each point in the N x 3, you would want to know the indices of the voxel it would fall into on the grid.
Once the 3D indices are known, you can take them two at a time as indices for accumarray(), setting the default value to NaN, and telling accumarray() to use either @max or @min as the function (depending on the side you want to look from.) For each pair of dimensions, this gives you a 2D grid that tells you, by index, which of the cuboids would be the "first" you would see if you were looking from that side. Use the non-NaN indices to convert to corresponding spatial coordinates in the dimension that you collapsed.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by