Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
"I don't know the effect of MeshFunctions." Have you looked it up in the documentation to try to understand what it does? –  Szabolcs Mar 25 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. –  Sigur Mar 25 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). –  Szabolcs Mar 25 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. –  Sigur Mar 25 at 23:59
1  
You may want to play around with BoxRatios to make it actually look like an ellipsoid. –  episanty Mar 26 at 12:46

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
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). –  Sigur Mar 26 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]]]

enter image description here

share|improve this answer
    
Great! Is it possible to show/hide the sphere? –  Sigur Mar 26 at 0:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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