How to fix the incorrect shape of a mesh

2 次查看(过去 30 天)
I have 3D points that represent a cuboid saved in F which I extracted from an image. F is 8x3 double array. When I converted the data to a triangulated mesh and plotted it, I got this incorrect shape, see the image below. It should produce a cuboid with 6 faces, but the resulted one has 8 faces. Anyone can help me how to fix the problem to plot the correct shape? However, when I write the values of x,y, and z manually (see the code below the image), the code plots the shape correctly.
The code is:
x = F(:,1);
y = F(:,2);
z = F(:,3);
shp = alphaShape(x,y,z);
[elements,nodes] = boundaryFacets(shp);
model = createpde(); % requires Partial Differential Equation Toolbox
geometryFromMesh(model,nodes',elements');
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5)
generateMesh(model);
% This section is the manual values of x, y, and z. Here the plot is correct. But if I use the existed one, the plot is not correct
F = [0.014 -0.4472 0
0.4055 -0.4472 0
0.409 -0.6478 0
0.014 -0.6478 0
0.014 -0.4472 -0.18
0.4055 -0.4472 -0.18
0.409 -0.6478 -0.18
0.014 -0.6478 -0.18];

采纳的回答

Mohammad Abu Haifa
I found the answer. To fix this problem we need to arrange the vertices order. So, you can do the following:
K = convhull(x,y,z);
nodes = [x';y';z'];
elements = K';
model = createpde();
geometryFromMesh(model,nodes,elements);
pdegplot(model,'FaceLabels','on','FaceAlpha',0.5)

更多回答(1 个)

KSSV
KSSV 2022-9-1
You need to arrange the vertices in an order...get the order from the above file exchange..
  2 个评论
Mohammad Abu Haifa
This is a different story. I want to keep it as a mesh (not only a plot) because I want to export the mesh to nother software. The problem is the number of faces of the mesh is correct when I enter the values manually, but when I use the 3D data extracted from an image, the mesh has two more faces.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by