How to generate a surface from xyz coordinates of triangular mesh nodes
조회 수: 37 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
> 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))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Geometry and Mesh에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!