10
$\begingroup$

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.

enter image description here

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

enter image description here

and (after reading some comments) I discovered that I can plot those two planes together simply using {h == 0, g == k, g == 0} obtaining

enter image description here

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?


ps: I edited the post to help future readings and to follow the rich comments.

$\endgroup$
6
  • $\begingroup$ "I don't know the effect of MeshFunctions." Have you looked it up in the documentation to try to understand what it does? $\endgroup$
    – Szabolcs
    Mar 25, 2014 at 23:55
  • $\begingroup$ @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. $\endgroup$
    – Sigur
    Mar 25, 2014 at 23:56
  • $\begingroup$ 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). $\endgroup$
    – Szabolcs
    Mar 25, 2014 at 23:57
  • $\begingroup$ I'm trying to show hoe to obtains the surfaces (spheres, paraboloid, cones and so on) starting with their intersections with coordinate planes. $\endgroup$
    – Sigur
    Mar 25, 2014 at 23:59
  • 1
    $\begingroup$ You may want to play around with BoxRatios to make it actually look like an ellipsoid. $\endgroup$ Mar 26, 2014 at 12:46

3 Answers 3

7
$\begingroup$

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[0]]]]

plot

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.

$\endgroup$
1
  • $\begingroup$ 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). $\endgroup$
    – Sigur
    Mar 26, 2014 at 2:24
9
$\begingroup$
 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]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Great! Is it possible to show/hide the sphere? $\endgroup$
    – Sigur
    Mar 26, 2014 at 0:20
5
$\begingroup$

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]}]

enter image description here

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[13] -> None], {1, _} -> Directive[Thick, Red]}]]

enter image description here

Or use

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

to get

enter image description here

$\endgroup$

Your Answer

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

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