Controlling quality of discretized region meshes
In principal you should be able to do
r = RegionDifference[Ball[{0, 0, 0}], Ball[{0, 0, 1}]];
rp = RegionPlot3D[r, PlotPoints -> 50];
DiscretizeGraphics[rp]
Unfortunately, this does not work and is hopefully improved in a future version.
One thing you can do, however, is use the finite element mesh generator for this:
Needs["NDSolve`FEM`"]
m = ToElementMesh[r,
"BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 50},
"MeshOrder" -> 1]
You can then convert the ElementMesh to a MeshRegion simply by using
MeshRegion[m]
Note that in this case MeshRegion
does not show it's output since it's beyond a threshold (too big). It has some 300000 tetrahedron elements.
You can force it to display with
Show[MeshRegion[m]]
The "MeshOrder"
is set to one (= linear elements) and the "SamplePoints"
correspond to the PlotPoints
in RegionPlot
. There is more information about boundary mesh generation in ToBoundaryMesh, ToElementMesh, ElementMesh and the related mesh generation and element mesh visualization tutorial.
One last thing I should add, is that the 3D stuff does have some rough edges.
Update version 12.1:
In version 12.1 you can use the OpenCascadeLink to do the following:
Needs["OpenCascadeLink`"]
Needs["NDSolve`FEM`"]
r = RegionDifference[Ball[{0, 0, 0}], Ball[{0, 0, 1}]];
ocr = OpenCascadeShapeBooleanRegion[r]
(* OpenCascadeShapeExpression[3] *)
bmeshOC = OpenCascadeShapeSurfaceMeshToBoundaryMesh[ocr];
bmeshOC["Wireframe"[
"MeshElementStyle" -> Directive[FaceForm[Green], EdgeForm[Red]]]]
And even simpler, you can use:
mesh = ToElementMesh[r, "BoundaryMeshGenerator" -> "OpenCascade"]
mesh["Wireframe"[
"MeshElementStyle" -> Directive[FaceForm[Green], EdgeForm[Red]]]]
Here is a way to do what you want using DiscretizeGraphics
as suggested by @user21. No need to call NDSolve
FEM`
r = RegionDifference[Ball[{0, 0, 0}], Ball[{0, 0, 1}]]
rp = RegionPlot3D[r, PlotPoints -> 50]
Now we discretize the Graphics
object with the following clever replacements that somehow works:
DiscretizeGraphics[Normal[rp /. {(PlotRange -> _) :>
PlotRange -> All, (Lighting -> _) :> Lighting -> Automatic}]]
To get even finer mesh, increase PlotPoints
in RegionPlot
(this will increase the time it takes to render the RegionPlot
), then proceed as before. I used PlotPoints -> 100
for the image below: