# How to make ClipPlanes only affect one of the 3D objects?

In order to show the maximum hemisphere inscribed to a unit cuboid, I use the following code:

Show[ContourPlot3D[
30 - 12 Sqrt[6] + x (-6 + 2 Sqrt[6] + x) + y (-6 + 2 Sqrt[6] + y) +
z (-6 + 2 Sqrt[6] + z) == 0, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
Mesh -> None, PlotTheme -> "Classic",
ClipPlanes -> -{1, 1, 1, 3 (Sqrt[6] - 3)},
ClipPlanesStyle -> {Opacity[.5]}],
Graphics3D[{Red, Ball[{1, 4 - 3 Sqrt[3/2], 4 - 3 Sqrt[3/2]}, .1]},
Boxed -> False],
Graphics3D[{Green,
Sphere[{5 - 2 Sqrt[6], 2 - Sqrt[3/2], 2 - Sqrt[3/2]}, .1]},
Boxed -> False]
]


I add two sphere /ball 3D objects in order to indicate the edge of the hemisphere. But I don't want the balls being clipped too.

How can I avoid it?

ClipPlanes can be limited to specific primitives. In this case the easiest way is probably to pass them in as part of the contour style:

Show[
ContourPlot3D[
30 - 12 Sqrt[6] + x (-6 + 2 Sqrt[6] + x) + y (-6 + 2 Sqrt[6] + y) +
z (-6 + 2 Sqrt[6] + z) == 0, {x, 0, 1.1}, {y, 0, 1}, {z, 0, 1},
Mesh -> None, PlotTheme -> "Classic", BoundaryStyle -> None,
ContourStyle -> Directive[{
(* coerce to floating point because of, um, reasons *)
ClipPlanes -> -{1, 1, 1, 3 (Sqrt[6] - 3.)},
ClipPlanesStyle -> {Opacity[.5]}
}]
],
Graphics3D[{Red, Ball[{1, 4 - 3 Sqrt[3/2], 4 - 3 Sqrt[3/2]}, .1]},
Boxed -> False],
Graphics3D[{Green, Sphere[{5 - 2 Sqrt[6], 2 - Sqrt[3/2], 2 - Sqrt[3/2]}, .1]},
Boxed -> False]
]


• I am surprised that the coercing to floating point is very critical, or the ClipPlane will not work. How do you know that? do you have any explanation? thank you, it works now. – user6043040 Nov 21 '16 at 23:41
• Well, I didn't know it at first. I tried it as an exact number, and it didn't behave as I expected. Then I tried a simpler clip plane, and it did. So really, just the usual process for figuring out how to get something to work. – Brett Champion Nov 22 '16 at 14:57