How to fix the incorrect shape of a mesh

6 views (last 30 days)
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];

Accepted Answer

Mohammad Abu Haifa
Mohammad Abu Haifa on 1 Sep 2022
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)

More Answers (1)

KSSV
KSSV on 1 Sep 2022
You need to arrange the vertices in an order...get the order from the above file exchange..
  2 Comments
Mohammad Abu Haifa
Mohammad Abu Haifa on 1 Sep 2022
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.
KSSV
KSSV on 1 Sep 2022
Check the order of the vertices...

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!