Message Boards Message Boards

Volume inside a closed 2D Mesh?

Posted 11 years ago

Hello!

I would like to calculate the volume inside a closed 2D Mesh (imported from an .stl model). I have tried to use Region functions, or integrate over the ploted mesh, but I've been only able to calculate the area of the mesh (and not the volume inside). Any idea on how to solve my problem?

Thanks!

POSTED BY: Haikel B

Does the 2D mesh represent a triangulation, being the border of a convex and simply connected area? If the answer is yes, yes, yes, then you can gain from each triangle in the mesh an inequality, then put all inequalities connected by logical AND into Boole and Integrate that Boole.

Let's do that for the simplest 2D mesh enclosing a 3D area, the tetrahedron:

 In[10]:= Clear[r]
    r = Tetrahedron[{{0, 0, 0}, {2, -1, 5}, {4, 3, 1}, {5, 4, 4}}];
    Graphics3D[r, Axes -> True]

In[13]:= Volume[r]
Out[13]= 16/3

let's leave the comfort zone a little bit

In[15]:= Integrate[1, {x, y, z} \[Element] r]
Out[15]= 16/3

now even a bit more

In[26]:= RegionBounds[r]    
Out[26]= {{0, 5}, {-1, 4}, {0, 5}}

In[27]:= Integrate[Boole[RegionMember[r, {x, y, z}]], 
                   {x, Min[r[[1, All, 1]]], Max[r[[1, All, 1]]]}, 
                   {y, Min[r[[1, All, 2]]], Max[r[[1, All, 2]]]}, 
                   {z, Min[r[[1, All, 3]]], Max[r[[1, All, 3]]]}]
Out[27]= 16/3

still using a built-in function like RegionMember. Get rid of it by using the inequalities defined by the faces of the tetrahedron

In[34]:= (* get four plane equations with **right** orientation *)
Integrate[
 Boole[(Dot[Cross[r[[1, 2]] - r[[1, 1]], r[[1, 3]] - r[[1, 1]]], {x, y, z} - r[[1, 1]]] >= 0)
    && (Dot[Cross[r[[1, 3]] - r[[1, 2]], r[[1, 4]] - r[[1, 2]]], {x, y, z} - r[[1, 2]]] <= 0)
    && (Dot[Cross[r[[1, 3]] - r[[1, 1]], r[[1, 4]] - r[[1, 1]]], {x, y, z} - r[[1, 1]]] >= 0)
    && (Dot[Cross[r[[1, 2]] - r[[1, 1]], r[[1, 4]] - r[[1, 1]]], {x, y, z} - r[[1, 1]]] <= 0)], 
       {x, Min[r[[1, All, 1]]], Max[r[[1, All, 1]]]}, 
       {y, Min[r[[1, All, 2]]], Max[r[[1, All, 2]]]}, 
       {z, Min[r[[1, All, 3]]], Max[r[[1, All, 3]]]}]
Out[34]= 16/3
POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract