# RegionDifference of a sphere and pyramid - Not correctly specified

I would like to cut out a pyramid from the sphere with the following but somehow I am missing something due to an error "RegionDifference object is not a correctly specified region" Ultimately I would like to export this as an stl file.

Graphics3D[{Sphere[{0, 0, 1}],
Pyramid[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 2}}]}]

reg1 = Graphics3D[
Pyramid[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 2}}]]

reg2 = Graphics3D[Sphere[{0, 0, 1}]]

rr = RegionDifference[reg2, reg1];

RegionPlot3D[rr, PlotPoints -> 100]


## 1 Answer

Clear["Global*"]


Graphics and Graphics3D are not regions. The primitives (e.g., Pyramid, Sphere, Ball) are regions. A Sphere is just the thin shell, the filled-in solid object is a Ball. Since you are cutting the Pyramid out, I assume that you mean Ball rather than Sphere.

reg1 = Pyramid[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, {0, 0, 2}}];

reg2 = Ball[{0, 0, 1}];


The argument to RegionPlot3D must be a boolean predicate describing the region rather than a region.

RegionPlot3D[
Element[{x, y, z}, reg2] && ! Element[{x, y, z}, reg1],
{x, -1, 1}, {y, -1, 1}, {z, 0, 2},
PlotStyle -> Opacity[0.67],
PlotPoints -> 35,
MaxRecursion -> 5]


rr = RegionDifference[reg2, reg1];

Region[Style[rr, Opacity[0.67]],
PerformanceGoal -> "Quality"]
`

• Thanks for the clarity! Nov 12, 2021 at 20:01