Convert a tetrahedron mesh to triangular mesh or surface mesh.

49 views (last 30 days)
Hi,
I have a stl file and generated the 3d mesh using generatemesh from PDE toolbox. But the output is tetrahedron mesh, I need only the surface mesh for that stl. I need to do with pdetoolbox only, because generatemesh is giving finer details of the 3d object. Basic code which I have tried is below. msh has faces of (n,4). So I need a surface mesh from this, I need a output of (n,3) which row indicate a connection of 3 vertices on surface. Any help is much appreciated.
model = createpde(3);
importGeometry(model,'example.stl');
msh = generaeMesh(model,'GeometricOrder','linear');

Accepted Answer

John D'Errico
John D'Errico on 14 Oct 2019
Edited: John D'Errico on 14 Oct 2019
Easy. Assume that tess is an nx4 array, composed of references into the set of vertices.
Then surely is it true that:
facets = [tess(:,[1 2 3]);tess(:,[1 2 4]);tess(:,[1 3 4]);tess(:,[2 3 4])];
is a set of facets of those simplexes? So facets is the set of triangular facets as requested. But I think you asked for the outer boundary surface of the mesh.
The only problem is that some of those facets are replicated. That is, facets that are shared between a pair of touching simplexes will happen exactly twice. A facet that is on the surface will occur exactly once.
But in fact, these replicates are actually a good thing! If you are only looking for the surface triangulation, then you can discard those facets that occurred twice. It is important to sort them though. (Think! why?)
facets = sort(facets,2);
Now, how do we discard those duplicated?
facets = sortrows(facets);
duploc = find(all(diff(facets) == 0,2));
facets([duploc;duploc + 1],:) = [];
  3 Comments
John D'Errico
John D'Errico on 14 Oct 2019
I'm not sure why you need a reference, unless you don't know what a cross product is. Its pretty basic, just look it up on Wikepedia.
The point is, a facet is a plane, defined by three points. Any pair of those two points defines a vector. Thus consider the edge defined by points V1 & V2, and the edge defined by V1 and V3.
So what would the cross product of vectors V2-V1 and V3-V1 yield? (If you are doing these things, you should already know basics of computational geometry like this.)
A nice thing is that cross is actually vectorized, so if you have entire sets of vectors for each facet, you could even compute the entire set of all facet normals in one call. Well, if you read the help for cross, you can do so.
A minor point is to ensure that the normals are pointing outwards or inwards as you may desire. But that is just a multiply by -1 as necessary for each vector.
Naga Durga Harish Kanamarlapudi
Understood. I am a very beginner in 3d geometry trying to understand some basic things. Thanks for your reply. It is really helpful.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!