How to generate a surface from xyz coordinates of triangular mesh nodes
31 views (last 30 days)
Show older comments
I have a matrix ox xyz coordinates (XYZ_Points) that represents only the surface nodes of a cuboid. I want to convert this coordinates back to a surface, but what I generated has many rough lines all over the cuboid, I do not want to hide the lines because I need to show the meshed surface, Please, how can I generate a clean image like the one in the second figure? Attempts to use mesh or surf with the coordinates did not work. A possibility to add a colour matrix to determine the color of each triangle will also be great.
figure(1)
x = XYZ_Points(1,:); %x coordinates
y = XYZ_Points(2,:); %y coordinates
z = XYZ_Points(3,:); %z coordinates
DT = delaunayTriangulation(x',y',z');
tetramesh(DT,EdgeColor = [0 0 0]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1573327/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1573332/image.jpeg)
0 Comments
Accepted Answer
Adam Danz
on 20 Dec 2023
Edited: Adam Danz
on 20 Dec 2023
> how can I generate a clean image like the one in the second figure?
This solution creates a model container based on the convex hull of your original data points and generates a mesh based on the model. Requires Partial Differential Equation Toolbox.
I saved the data points from your mat file to a csv file so that I can load it here.
XYZ_Points = readmatrix('XYZ_Points.csv');
x = XYZ_Points(1,:); %x coordinates
y = XYZ_Points(2,:); %y coordinates
z = XYZ_Points(3,:); %z coordinates
K = convhull(x(:),y(:),z(:));
nodes = [x(:)';y(:)';z(:)'];
elements = K';
model = createpde();
geometryFromMesh(model,nodes,elements);
generateMesh(model);
pdeplot3D(model)
axis on
> A possibility to add a colour matrix to determine the color of each triangle will also be great.
Set FaceColor to flat and then the FaceVertexCData property will define the color of each face as an index value that indexes the colormap. This demo sets the color of each face based on the distance of each face to the center of the cube.
figure()
h = pdeplot3D(model);
% Distance to (center for cube
D = sqrt(sum((h.Vertices-mean(h.Vertices)).^2,2));
h.FaceColor = 'flat';
h.FaceVertexCData = D;
cb = colorbar();
ylabel(cb,'Distance to center')
colormap(turbo(256))
More Answers (0)
See Also
Categories
Find more on Geometry and Mesh in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!