6
$\begingroup$

When plotting a certain figure in Mathematica I noticed that some lines that should be straight ended up being curved in a certain periodic manner. I was hoping that somebody could help me fix this. A minimal working example of the code is provided below, with the resulting figure that Mathematica produces. I plot two parts of a hyperboloid $x^2+y^2-z^2=1$, namely the part with $y+z>0$ (green) and the part with $y+z<0$ (yellow). The lines where the two surfaces meet should be straight, but it has a certain periodic feature to it, which should not be there. Does anybody know how to fix this?

b = 5;
a = 10;

GreenPart = ContourPlot3D[
   -z^2 + x^2 + y^2 ==   1, {x, -a, a}, {y, -a, a}, {z, -a, a} , 
   RegionFunction -> 
    Function[{x, y, z}, y + z > 0  && z < b && z > -b], 
   ContourStyle -> RGBColor[0.0, 0.6, 0.1, 0.9],  Mesh -> None, 
   Axes -> False, Boxed -> False, AxesOrigin -> {0, 0, 0}
   ];
YellowPart = ContourPlot3D[
   -z^2 + x^2 + y^2 ==   1, {x, -a, a}, {y, -a, a} , {z, -a, a}, 
   RegionFunction -> 
    Function[{x, y, z}, (y + z < 0) && z < b && z > -b], 
   ContourStyle -> {RGBColor[1, 1, .0, .5]}, Mesh -> None, 
   Axes -> False, Boxed -> False, AxesOrigin -> {0, 0, 0}
   ];

Show[
 GreenPart, YellowPart,
 Graphics3D[
  {Red, Thickness[0.005], Arrowheads[0.03], 
   Arrow[{{0, 0, 0}, {b + 2, 0, 0}}], 
   Arrow[{{0, 0, 0}, {0, 0, b + 2}}], 
   Arrow[{{0, 0, 0}, {0, b + 2, 0}}]}
  ],
 Graphics3D[
  {Text[Style[x, 35, Italic, Bold, 
     FontFamily -> "Times New Roman"], {b + 3, 0, 0.2}], 
   Text[Style[y, 35, Italic, Bold, FontFamily -> "Times New Roman"],
     {0, b + 3, 0}], 
   Text[Style[z, 35, Italic, Bold, 
     FontFamily -> "Times New Roman"], {0, 0, b + 3.4}]}
  ],
 ImageSize -> Large,
 ViewPoint -> {2.5, 5, 1}
 ]

output of Mathematica as a result of the code above

$\endgroup$
6
$\begingroup$

It looks like it's just due to the inner interpolation. Simply adding PlotPoints -> 50 to GreenPart and YellowPart does the job.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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