5
$\begingroup$

How can I remove the cap of a sphere in graphics ?

Graphics3D[{Red, Sphere[{0, 0, 0}, 5]}, Axes -> True, PlotRange -> {{-10, 10}, {-10, 10}, {-10, 10}}]

I'd like to remove the green part for example here :

enter image description here

EDIT : After having an answer, I still have a problem when I want to chose the side it must cut. For instance

Graphics3D[{Sphere[]}, 
 ClipPlanes -> InfinitePlane[{{0, 1, 0.8}, {2, 0, 0.8}, {0, 0, 0.8}}]]

cuts the top. But what if I want to cut the bottom. So I know I could cut at $-0.8$ and return. But if I want to cut the two caps at the top and the bottom how could I proceed ?

$\endgroup$
3
  • 5
    $\begingroup$ See the first example for ClipPlanes. $\endgroup$ – Jason B. May 28 '20 at 15:58
  • $\begingroup$ Have you read through the documentation for ClipPlanes as suggested by @JasonB.? The "Neat Examples" section demonstrates how to cut multiple planes – you just have to specify a list of planes to cut. $\endgroup$ – MassDefect May 28 '20 at 19:14
  • 1
    $\begingroup$ You can change the orientation of the plane by permuting points. e.g. Graphics3D[{Sphere[]}, ClipPlanes -> InfinitePlane[{{2, 0, 0.8}, {0, 1, 0.8}, {0, 0, 0.8}}]] $\endgroup$ – Chip Hurst May 28 '20 at 21:42
6
$\begingroup$

You can specify ClipPlanes as a 4-tuple (or as a list of 4-tuples) to control the directions more conveniently. It is also more convenient to use ClipPlanes as a directive (rather than an option) to specify multiple clip planes for a given primitive:

ClipPlanes >> Details

enter image description here

Graphics3D[{ClipPlanes -> {{0, 0, -1, .8}, {0, 0, 1, .7}, {1, 1, 1, 1.5}}, 
 Opacity[.7], Sphere[]}, 
 Axes -> True, Ticks -> {Automatic, Automatic, {-.7, .8 }}]

enter image description here

Add the option

ClipPlanesStyle -> (Opacity[.5, #] & /@ {Red, Blue, Green})

to see the three clipping planes:

enter image description here

Update: A function to flip the side that is cut away by a clip plane:

ClearAll[flipSide]
flipSide[{a_?NumericQ, b_, c_, d_}] := -{a, b, c, d};
flipSide[ip_InfinitePlane] := MapAt[#[[{2, 1, 3}]] &, ip, {1}];

Graphics3D[{{Red, ClipPlanes -> {{1, 0, 1, -.8}}, Opacity[.7], 
   Sphere[]}, {Green, ClipPlanes -> {flipSide@{1, 0, 1, -.8}}, 
   Opacity[.7], Sphere[]}}, Axes -> True, ImageSize -> Medium]

enter image description here

Graphics3D[{{Red, ClipPlanes -> {InfinitePlane[{{0, 0, 0}, {0, 1, 1}, {1, 1, 2}}]}, 
   Opacity[.7], Sphere[]}, 
  {Green, ClipPlanes -> {flipSide@
      InfinitePlane[{{0, 0, 0}, {0, 1, 1}, {1, 1, 2}}]}, Opacity[.7], 
   Sphere[]}}, Axes -> True, ImageSize -> Medium]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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