1
$\begingroup$

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]
$\endgroup$

1 Answer 1

2
$\begingroup$
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]

enter image description here

rr = RegionDifference[reg2, reg1];

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

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for the clarity! $\endgroup$ Nov 12, 2021 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.