Dear all, here is a simplified example of my problem: I have a 2D mesh structure embedded in 3D space, therefore its volume is 0. Let the mesh structure be:
sphereMesh = DiscretizeGraphics[Sphere[]]
with the above mentioned properties:
Through[{Volume, RegionDimension, RegionEmbeddingDimension}[sphereMesh]]
(* Out: {0,2,3} *)
The head of sphereMesh is MeshRegion. For calculating the (included) volume I need to convert this into a BoundaryMeshRegion (at least I think so …), but I was not able to achieve this. Can anyone give me a hint on how to do this, or how to calculate this included volume in an other way?
Many thanks! – Henrik
sukrause
(Udo Krause)
October 6, 2015, 9:33pm
2
If you can make the 2D mesh into a BoundaryMeshRegion then you can call its Volume.
Dear Udo,
thank you for your quick response! But your answer was exactly my question. I do no know how to convert this MeshRegion into a BoundaryMeshRegion:
BoundaryMesh[sphereMesh]
does not work. Inspecting the FullForm of sphereMesh gives the impression that one just has to replace the head of sphereMesh like so:
BoundaryMeshRegion @@ sphereMesh
but this is working neither because (for a reason I cannot understand) sphereMesh is an Atom.
Regards – Henrik
I just found a working “solution” which I would qualify as really dirty :
boundarySphereMesh = ToExpression @ StringReplace[ToString@InputForm[sphereMesh], "MeshRegion" -> "BoundaryMeshRegion"]
But basically my question remains: How can this be achieved in a clean way? I do not believe that this dirty method is always working.
jfriedman
(Jesse Friedman)
October 7, 2015, 10:25am
5
I think BoundaryDiscretizeGraphics is what you’re looking for.
sukrause
(Udo Krause)
October 8, 2015, 7:19pm
6
But your answer was exactly my question.
Not at all, because one creates a BoundaryMeshRegion from the given data just by
In[121]:= BoundaryMeshRegion[MeshCoordinates[#], MeshCells[#, 2]] &[DiscretizeGraphics[Sphere[]]]
In[122]:= Volume[%]
Out[122]= 4.15297
Dear Jesse,
you are right! I first hesitated the detour going from mesh to graphics and back to mesh, but maybe this is the only way:
sphereMesh = DiscretizeGraphics[Sphere[]]; (* ... as an example *)
spherePrim = MeshPrimitives[sphereMesh, 2];
sphereBoundary = BoundaryDiscretizeGraphics[spherePrim];
Through[{Head, Volume, RegionDimension, RegionEmbeddingDimension}[sphereBoundary]]
(* Out: {BoundaryMeshRegion,4.152965792075726`,3,3} *)
Thank you four your suggestion! Regards – Henrik
Dear Udo,
thank you very much for taking the time looking into this problem! Meanwhile - as you can see in the response to Jesse - a solution was found. I used Sphere[] just as an example. My actual problem deals with a much more complicated mesh structure for which there is no analytical expression (therefore something like ImplicitRegion[] is not possible).
Regards – Henrik
This discussion might of interest : “Find the volume of Phobos and Deimos” .
Here is an application of the prescribed solution in the answer by Bob Werner in that discussion:
coords = MeshCoordinates[sphereMesh];
cells = MeshCells[sphereMesh, 2];
Total[Abs[cells /. Polygon[x__] :> Det[coords[[x]]]]]/6
(* Out[10]= 4.15297 *)
Dear Anton, dear Udo,
thank you very much for your suggestions! Those are exactly the kind of solutions I was hoping to find!
Regards – Henrik