# DiscretizeRegion was unable to discretize the region ImplicitRegion

I'm trying to model a 3D die with ImplicitRegion[] in order to find out its center of mass. However, when I apply RegionCentroid[] to this region it takes too long to give an output. So I thought DiscretizeRegion[] would might render the computation of the centroid easier without losing precision.

θ=(63/100)Pi;
depth=9/10;
r = 22/10;
offset = 1/2;
offset61 = 3/10;
offset62 = 6/10;
ℛ= ImplicitRegion[
(*Cube*)
-1<=x<=1 &&
-1<=y<=1 &&
-1<=z<=1 &&
(*Sphere*)
x^2+y^2+z^2<=r&&
(* face 1*)
Not[(x^2+y^2)(Cos[θ]^2)-((Sin[θ]^2)((z-depth)^2))<=0&&0<(z-depth)<=1] &&
(* face 2*)
Not[((x-offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y+depth)^2))<=0&&-1<(y+depth)<=0]&&
Not[((x+offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y+depth)^2))<=0&&-1<(y+depth)<=0]&&
(*face3*)
Not[((y-offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x+depth)^2))<=0&& -1<(x+depth)<=0]&&
Not[((y)^2+(z)^2)(Cos[θ]^2)-((Sin[θ]^2)((x+depth)^2))<=0&& -1<(x+depth)<=0]&&
Not[((y+offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x+depth)^2))<=0&& -1<(x+depth)<=0]&&
(*face4*)
Not[((y-offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x-depth)^2))<=0&& 0<(x-depth)<=1]&&
Not[((y+offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x-depth)^2))<=0&& 0<(x-depth)<=1]&&
Not[((y+offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x-depth)^2))<=0&& 0<(x-depth)<=1]&&
Not[((y-offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((x-depth)^2))<=0&& 0<(x-depth)<=1]&&
(* face 5*)
Not[((x-offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y-depth)^2))<=0&&0<(y-depth)<=1]&&
Not[((x)^2+(z)^2)(Cos[θ]^2)-((Sin[θ]^2)((y-depth)^2))<=0&&0<(y-depth)<=1]&&
Not[((x-offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y-depth)^2))<=0&&0<(y-depth)<=1]&&
Not[((x+offset)^2+(z+offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y-depth)^2))<=0&&0<(y-depth)<=1]&&
Not[((x+offset)^2+(z-offset)^2)(Cos[θ]^2)-((Sin[θ]^2)((y-depth)^2))<=0&&0<(y-depth)<=1]&&
(*face 6*)
Not[((x+offset62)^2+(y+offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]&&
Not[((x-offset62)^2+(y+offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]&&
Not[((x+offset62)^2+(y-offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]&&
Not[((x-offset62)^2+(y-offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]&&
Not[((x)^2+(y+offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]&&
Not[((x)^2+(y-offset61)^2)(Cos[θ]^2)-((Sin[θ]^2)((z+depth)^2))<=0&&-1<(z+depth)<=0]
, {x,y,z}];
(*b=RegionPlot3D[ℛ,Axes->True, AxesLabel->{x,y,z},PlotStyle->Directive[Opacity[0.9]], PlotPoints->100]*)


When I try to discretize this region I get the following error:

DiscretizeRegion::drf: DiscretizeRegion was unable to discretize the region ImplicitRegion[<<2>>].

I'd like to know:

1. How to circumvent this error?
2. Is there a better method to obtain the centroid of this solid?

You can use the Finite Element mesh generator.

Needs["NDSolveFEM"]
mesh = ToElementMesh[\[ScriptCapitalR]]


That already gives a hint to what the problem is because ToElementMesh does not Quiet everything away. Then using the following returns something that does not look terrible:

mesh = ToElementMesh[\[ScriptCapitalR], {{-1.1, 1.1}, {-1.1,
1.1}, {-1.1, 1.1}}];
mesh["Wireframe"]


We can convert that to a MeshRegion:

Computing the center

rc = RegionCentroid[MeshRegion[mesh]]
{-0.0007281574436766132, -0.00209881562008262, \
0.0035201682587072554}


Looks like it is slightly off center. I'd play a bit with the boundary resolution to see how much that affects the result.

A visual:

Show[
mesh["Edgeframe"],
Graphics3D[{Red, PointSize[0.02], Point[rc]}]
]


I did not get very far with a symbolic integration; try numeric integration. You may want to experiment with giving bounds to the ImplicitRegion.

For the statistics buffs: What are my odds for what numbers?

• The only thing is that ToElementMesh gave me a "unable to discretize ImplicitRegion" error and a very coarse mesh, unlike yours... Nov 28, 2018 at 2:28
• @Fred what version are you on? Nov 28, 2018 at 7:01
• Version: 11.3.0.0 (Student Edition); Platform: Mac OS X x86 (32-bit, 64-bit Kernel) Nov 28, 2018 at 14:06
• @Fred, just double checking this is with the bounds specified to ToElementMesh[R,bounds], right. What happens if you use SetSystemOptions[ "FiniteElementOptions" -> {"SymbolicProcessing" -> 10.}]`. If that does not help. I'd send this in to support. Nov 28, 2018 at 14:15
• I got "FiniteElementOptions" -> {"CacheInterpolationElements" -> True, "DefaultBounds" -> {-1, 1}, "DefaultElementMeshOrder" -> 2, "DefaultExtrapolationHandler" -> {Indeterminate &, "WarningMessage" -> True}, "DefaultNumberOfElements" -> 20, "InterpolationToleranceFactor" -> 0.0001, "MinimumElementMeshQuality" -> 0., "SymbolicProcessing" -> 10.} and reevaluated everything... Still the same. I've included the bounds {{-1.1, 1.1}, {-1.1, 1.1}, {-1.1, 1.1}} Nov 28, 2018 at 14:26