Meshing a volume into tetrahedrons
Show older comments
I am trying to mesh a simple volume (into tetrahedrons. I obtained the 3D geometry by extruding a 2-D geometry. From what I understand I can only mesh a volume by first writing an stl-file, then importing it into MATLAB and then meshing the volume. But how do I export my 3-D geometry to an stl-file?
I somehow managed successfully to mesh the brick without the hole using the function Delaunay, triangulation and stl-write.
Below is some code.
Thank you so much for any help you could offer
Ansgar
%exterior boundary
x = [-4 4 4 -4];
y = [-4 -4 4 4];
%interior boundary
x1 = [0 -2 0 2];
y1 = [-2 0 2 0];
R1 = [2;4;x';y'];
R2 = [2;4;x1';y1'];
gm =[R1 R2];
sf = 'R1-R2';
ns = char('R1','R2')'
g = decsg(gm,sf,ns)
model = createpde;
g1=geometryFromEdges(model,g)
%meshing the area works fine
mesh=generateMesh(model,'GeometricOrder','linear','Hmax',1,'Hmin',.3)
pdeplot(model)
g2=extrude(g1,1)
figure
pdegplot(g2,'FaceLabels','on','facealpha',.2)
%***********************
%where do I go from here
%***********************
%stlwrite, delaunay ??????
Answers (1)
Tushar
on 22 Aug 2023
Hi Ansgar,
I understand that you are looking for meshing the volume into tetrahedrons. But tetrahedron triangulation is not supported by 'stlwrite'. However, you can follow the steps below to get started:
- Extract the vertices from the 3D model, using the Vertices property of 'DiscreteGeometry' object:
X_=g2.Vertices(:,1);
Y_=g2.Vertices(:,2);
- Use the 'delaunayTriangulation' object to create a 2-D or 3-D 'Delaunay triangulation' from the set of vertices as follows:
DT=delaunayTriangulation([X_,Y_]);
- Explore the 'ConnectivityList' Property of the object DT.
- (optional step) Using the connectivity list as stated above, create a 'triangulation' object:
tri=triangulation(DT.ConnectivityList,X_,Y_);
- Finally, using the 'stlwrite' function, output this geometry into an STL file:
stlwrite(tri,"output.stl");
Categories
Find more on Triangulations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
