How to create "Volumemesh" from closed "surfacemesh"?
I expect the following to work only in a few cases. It works here.
Extract the polygons and re-make them into a BoundaryMeshRegion
:
bm = BoundaryMeshRegion[MeshCoordinates[netz2D], MeshCells[netz2D, 2]]
Then you can triangulate the interior:
TriangulateMesh[bm]
A better way to achieve the same would have been:
BoundaryDiscretizeRegion@ImplicitRegion[x^2 + y^2 + z^2 <= 1, {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}]
The important thing is to keep surface meshes as BoundaryMeshRegion
s, not as MeshRegion
s. This way we maintain information about the interior.
bild2 = DiscretizeRegion[ImplicitRegion[x^2 + y^2 + z^2 <= 1,
{{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}],
MeshCellStyle -> {{2, All} -> Opacity[.5]}]
RegionDimension[bild2]
3
Depending a bit on what you want to do you could use the FEM mesh, that can be made more accurate than a DiscretizeRegion
approach.
Needs["NDSolve`FEM`"]
reg = ImplicitRegion[
x^2 + y^2 + z^2 <= 1, {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}];
bild2 = ToElementMesh[reg, "ImproveBoundaryPosition" -> True];
vol = \[Pi]/6;
vol - Total[bild2["MeshElementMeasure"], 2]
6.633774715880669`*^-6
vol - RegionMeasure[DiscretizeRegion[reg]]
0.0004287579660063878`
For 3D the Automatic setting for "ImproveBoundaryPosition" is False (for 2D it is True) and with this improved boundary you get a much more accurate representation of the region. This is useful if you want to numerically solve PDEs or integrate over the region.
Also note that the workflow for ElementMesh
is more intuitive as the boundary mesh can be made to a full mesh:
bmesh = ToBoundaryMesh[reg];
ToElementMesh[bmesh];
If you want the same accuracy as above you'd use ToNumericalRegion
to connect the region and the boundary mesh.
You can think of a BoundaryMeshRegion
as a sparse representation of a full region. A boundary element mesh is different; it is a representation of the boundary of the region. As a consequence you can do this:
bmesh = ToBoundaryMesh[Circle[{0, 0}, 1, {Pi/6, 3 Pi/4}]];
NIntegrate[1, Element[{x, y}, bmesh]]
1.8323249230952223`
But not this:
ToElementMesh[bmesh]
$Failed
Note that if the boundary is closed
bmesh = ToBoundaryMesh[Circle[{0, 0}, 1]];
Then ToElementMesh
will generate a full mesh.
Head[ToElementMesh[bmesh]]
ElementMesh
To get to your question, that's why this works:
ToElementMesh[RegionBoundary[netz2D]]
bild2 = ToElementMesh[
ImplicitRegion[
x^2 + y^2 + z^2 <= 1, {{x, 0, 1}, {y, 0, 1}, {z, 0, 1}}]];
Look at the wire frame of the surface elements:
bild2["Wireframe"]
Look at the wire frame of the full mesh:
bild2["Wireframe"["MeshElement" -> "MeshElements"]]
Or if you want a MeshRegion:
MeshRegion[ToElementMesh[RegionBoundary[netz2D], "MeshOrder" -> 1]]