I'm trying to plot 2 spheroids that connect smoothly at z=0 and show spheroid1 where z>0 and show spheroid2 where z<0. But I can't differentiate the two according to the z range. This is my code.

Module[{a = 1.12*10^-3, b = 1.09*10^-3, c = 0.82*10^-3, 
  z0 = 0.73*10^-3},
 ContourPlot3D[{(x^2 + y^2)/a^2 + z^2/b^2 == 
    1, (x^2 + y^2)/a^2 + z^2/c^2 == 1},
  {x, -1.5 a, 1.5 a}, {y, -1.5 a, 1.5 a}, {z, -c, b},
  RegionFunction -> Function[{x, y, z}, x < 0 || y > 0],
  AxesLabel -> {x, y, z},
  ContourStyle -> {Yellow, Magenta}]
 ]

I would like to see the yellow part at z>0 and the magenta part at z<0

(would like to plot only the upper half of the yellow part and the lower half of the magenta) enter image description here

share|improve this question
    
Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey 5 hours ago

The desired plot can be obtained by a single call to ContourPlot3D by plotting only the top half of the outer spheroid and the bottom half of the inner spheroid, each with its own color.

Module[{a = 1.12*10^-3, b = 1.09*10^-3, c = 0.82*10^-3, 0 = 0.73*10^-3},
    ContourPlot3D[(x^2 + y^2)/a^2 + If[z > 0, z^2/b^2 , z^2/c^2] == 1, 
    {x, -1.5 a, 1.5 a}, {y, -1.5 a, 1.5 a}, {z, -c, b},
    RegionFunction -> Function[{x, y, z}, x < 0 || y > 0],
    AxesLabel -> {x, y, z}, LabelStyle -> {14, Bold}, ColorFunctionScaling -> False,
    ColorFunction -> Function[{x, y, z, f}, If[z > 0, Yellow, Magenta]]]
]

enter image description here

share|improve this answer
    
thank you for the reply! – Jun 10 hours ago
    
+1; although I recommend using Piecewise rather than If in a function/equation. Piecewise is better behaved, e.g., it can be differentiated. – Bob Hanlon 4 hours ago

You may use the ClipPlanes option in ContourStyle. However in version 11.0.1 the MeshStyle and BoundaryStyle do not consider the ContourStyle ClipPlanes option so must be set to None to prevent plotting extra mesh lines. I think this may be a bug.

Module[{a = 1.12*10^-3, b = 1.09*10^-3, c = 0.82*10^-3, z0 = 0.73*10^-3},
 ContourPlot3D[
  {(x^2 + y^2)/a^2 + z^2/b^2 == 1,
   (x^2 + y^2)/a^2 + z^2/c^2 == 1},
  {x, -1.5 a, 1.5 a}, {y, -1.5 a, 1.5 a}, {z, -c, b},
  RegionFunction -> Function[{x, y, z}, x < 0 || y > 0],
  AxesLabel -> {x, y, z},
  ContourStyle -> {
    {Yellow, ClipPlanes -> {{0, 0, 1, 0}}},
    {Magenta, ClipPlanes -> {{0, 0, -1, 0}}}
    },
  MeshStyle -> None,
  BoundaryStyle -> None
  ] ]

Mathematica graphics

Hope this helps.

share|improve this answer
    
thank you for the reply! – Jun 10 hours ago

Use Show to display two separate plots

Module[
 {a = 1.12*10^-3, b = 1.09*10^-3,
  c = 0.82*10^-3, z0 = 0.73*10^-3, m},
 m = 3 a/2;
 Show[
  ContourPlot3D[
   (x^2 + y^2)/a^2 + z^2/b^2 == 1,
   {x, -m, m}, {y, -m, m}, {z, -c, b},
   RegionFunction ->
    Function[{x, y, z}, z > 0 && (x < 0 || y > 0)],
   ContourStyle -> Yellow],
  ContourPlot3D[
   (x^2 + y^2)/a^2 + z^2/c^2 == 1,
   {x, -m, m}, {y, -m, m}, {z, -c, b},
   RegionFunction ->
    Function[{x, y, z}, z < 0 && (x < 0 || y > 0)],
   ContourStyle -> Magenta],
  AxesLabel ->
   (Style[#, 14, Bold] & /@ {x, y, z}),
  PlotPoints -> 75]]

enter image description here

share|improve this answer
    
thank you for the reply! – Jun 10 hours ago

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.