# Intersection of surface with parallel planes

Consider the code (adapted from here)

h = x^2 + y^2/9 + z^2/4 - 1;
g = z;
ContourPlot3D[
{h == 0, g == 0}, {x, -1, 1}, {y, -3, 3}, {z, -2, 2},
MeshFunctions -> {Function[{x, y, z, f}, h - g]},
MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}},
ContourStyle -> Directive[Orange, Opacity[0.5], Specularity[White, 30]]]


Now I have few ideas on the effect of MeshFunctions. Anyway, the result is very nice for me. I'd like to do the same but with a parallel plane with $z=k$ for other values of $k$ (for example, $k=1$).

So I tried the code

h = x^2 + y^2/9 + z^2/4 - 1;
g = z;
k := 1;
ContourPlot3D[
{h == 0, g == k}, {x, -1, 1}, {y, -3, 3}, {z, -2, 2},
MeshFunctions -> {Function[{x, y, z, f}, h - g]},
MeshStyle -> {{Thick, Blue}}, Mesh -> {{0}},
ContourStyle -> Directive[Orange, Opacity[0.5], Specularity[White, 30]]]


and the result was and (after reading some comments) I discovered that I can plot those two planes together simply using {h == 0, g == k, g == 0} obtaining Question: How to get the sphere (to be true, an ellipsoid) together with two or three planes corresponding to different values of $k$ and their intersection (the blue curves) all on the same figure?

• "I don't know the effect of MeshFunctions." Have you looked it up in the documentation to try to understand what it does? Mar 25, 2014 at 23:55
• @Szabolcs, not yet. I was supposing that code was not relevant for the intersection. But based on your question I guess that I was wrong. I'll read it. Mar 25, 2014 at 23:56
• There's an example which probably gives what you want in the documentation of ContourPlot3D under MeshFunctions. Although you did not actually say what you wanted to do (it is not obvious to me, I'm just guessing). Mar 25, 2014 at 23:57
• I'm trying to show hoe to obtains the surfaces (spheres, paraboloid, cones and so on) starting with their intersections with coordinate planes. Mar 25, 2014 at 23:59
• You may want to play around with BoxRatios to make it actually look like an ellipsoid. Mar 26, 2014 at 12:46

It appears that you are interested in showing only the intersections for an arbitrary set of cutting planes parallel to the xy-plane. That can be achieved by making some small modifications to PatoCriollo's answer. Like so:

h = x^2 + y^2/9 + z^2/4 - 1;
With[{cuts = Range[-5/2, 5/2, 1/2]},
ContourPlot3D[h == 0, {x, -1, 1}, {y, -3, 3}, {z, -2, 2},
MeshFunctions -> {Function[{x, y, z, f}, z]},
MeshStyle -> {{Thick, Blue}}, Mesh -> {cuts},
ContourStyle -> Directive[Opacity]]] ### Edit

On second thought, there is no need for g at all. The code above has been edited to eliminate g. This is much faster.

• lol perfect! Now I can teach my students about quadratic surfaces. Thanks so much. I'll try to adapt it to show other circles for other planes ($x$ or $y$ constants). Mar 26, 2014 at 2:24
 h = x^2 + y^2/9 + z^2/4 - 1;
g = z;
ContourPlot3D[{h == 0, g == 0, g == k}, {x, -1, 1}, {y, -3,
3}, {z, -2, 2}, MeshFunctions -> {Function[{x, y, z, f}, z]},
MeshStyle -> {{Thick, Blue}}, Mesh -> {{0, k }},
ContourStyle ->
Directive[Orange, Opacity[0.5], Specularity[White, 30]]] • Great! Is it possible to show/hide the sphere? Mar 26, 2014 at 0:20

Using BoundaryStyle only:

You can use BoundaryStyle to mark the intersections of the contour surfaces:

h = x^2 + y^2/9 + z^2/4 - 1;
ContourPlot3D[{h == 0, z == 0}, {x, -1, 1}, {y, -3, 3}, {z, -2, 2},
Mesh -> None, ContourStyle -> Directive[Orange, Opacity[0.5], Specularity[White, 30]],
BoundaryStyle -> {1 -> None, 2 -> None, {1, _} -> Directive[Thick, Blue]}] This also works with multiple contour planes:

ContourPlot3D[Evaluate@Prepend[Thread[z == Range[-2, 2, .4]], h == 0],
{x, -1,  1}, {y, -3, 3}, {z, -2, 2}, Mesh -> None,  ContourStyle -> None,
BoundaryStyle -> Flatten[{Thread[Range -> None], {1, _} -> Directive[Thick, Red]}]] Or use

  ContourStyle -> Thread[Directive[Opacity[.2], RandomColor]]
(*  Hue /@ RandomReal[1, 13] instead of RandomColor in version 9 *)


to get 