Borrar filtros
Borrar filtros

How to generate a surface from xyz coordinates of triangular mesh nodes

37 visualizaciones (últimos 30 días)
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]);

Respuesta aceptada

Adam Danz
Adam Danz el 20 de Dic. de 2023
Editada: Adam Danz el 20 de Dic. de 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
For more info and a similar example, see documentation pages for generateMesh and geometryFromMesh.
> 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))
  1 comentario
Ade Ade
Ade Ade el 20 de Dic. de 2023
@Adam Danz Although, the number and position of the mesh elements are not exactly the same with the old coordinates, but this gave me the perfect idea.Thank you for this approach, especially for the FaceVertexCData parameter.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by