MATLAB Answers

Convert a tetrahedron mesh to triangular mesh or surface mesh.

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);
msh = generaeMesh(model,'GeometricOrder','linear');

  댓글 수: 0

로그인 to comment.

답변 수: 1

John D'Errico 님의 답변 14 Oct 2019
John D'Errico 님이 편집함. 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

Amazing. This is exactly what I need. Thanks a lot for your answer. Any references to get normals for each vertex/facet?
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.
Understood. I am a very beginner in 3d geometry trying to understand some basic things. Thanks for your reply. It is really helpful.

로그인 to comment.

Translated by