필터 지우기
필터 지우기

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

조회 수: 37 (최근 30일)
Ade Ade
Ade Ade 2023년 12월 20일
편집: Adam Danz 2023년 12월 20일
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]);

채택된 답변

Adam Danz
Adam Danz 2023년 12월 20일
편집: Adam Danz 2023년 12월 20일
> 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
Ade Ade
Ade Ade 2023년 12월 20일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by