8
$\begingroup$

I was using MeshFunctions to get intersection of quadratic with plane, but am getting some unexpected curves, any idea how to get rid of them, or maybe a more elegant way to achieve this effect?

genPlot[theta_] := (
   plot1 = 
    Plot3D[3 x^2 + y^2, {x, -2, 2}, {y, -2, 2}, 
     MeshFunctions -> {#3 &, If[#1 != 0, ArcTan[#1, #2], -1] &}, 
     MeshStyle -> {Automatic, Thick}, 
     Mesh -> {5, {theta, theta - Pi}}, Boxed -> False, Axes -> False, 
     RegionFunction -> Function[{x, y, z}, x^2 + y^2 < 3], 
     PlotPoints -> 25];
   point = 2 {Cos[theta], Sin[theta], 0};
   
   plot2 = 
    Graphics3D[{Opacity[.5], EdgeForm[None], 
      Polygon[{-point, point, 
        point + {0, 0, 10}, -point + {0, 0, 10}}]}];
   Show[plot1, plot2, SphericalRegion -> True]
   );
genPlot[Pi/4]

edit Brett's solution below fixes it (notebook)

$\endgroup$
10
$\begingroup$

MeshFunctions works by detecting where the function crosses your values, in this case where ArcTan becomes equal to theta. Unfortunately this is done numerically, checking sign changes, and so the branch cut along the negative $y$ axis is included. (It goes from $-\pi$ to $\pi$, so must have crossed theta somewhere in there, right?)

The cleanest solution I've found for removing it in your example is to rotate the branch cut to align along where you want to draw the mesh line by using Mod[ArcTan[#1, #2], 2 Pi, theta] for the mesh function:

genPlot[theta_] := (plot1 = 
    Plot3D[3 x^2 + y^2, {x, -2, 2}, {y, -2, 2}, 
     MeshFunctions -> {#3 &, Mod[ArcTan[#1, #2], 2 Pi, theta] &}, 
     MeshStyle -> {Automatic, Thick}, 
     Mesh -> {5, {theta, theta + Pi}}, Boxed -> False, Axes -> False, 
     RegionFunction -> Function[{x, y, z}, x^2 + y^2 < 3], 
     PlotPoints -> 25];
   point = 2 {Cos[theta], Sin[theta], 0};
   plot2 = 
    Graphics3D[{Opacity[.5], EdgeForm[None], 
      Polygon[{-point, point, 
        point + {0, 0, 10}, -point + {0, 0, 10}}]}];
   Show[plot1, plot2, SphericalRegion -> True]);
genPlot[Pi/4]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks! BTW, any tips how to get rid of that artifact on the left edge of the bowl? (right above the bold curve) $\endgroup$ Sep 10 '21 at 22:53
  • 1
    $\begingroup$ This gets rid of that artifact: Plot3D[3 x^2 + y^2, {x, y} \[Element] BoundaryDiscretizeRegion[Disk[{0, 0}, Sqrt[3]], AccuracyGoal -> 5], opts], where opts omits the RegionFunction option. Note that the call to BoundaryDiscretizeRegion is not necessary, but I added it to make the boundary smoother. $\endgroup$
    – Greg Hurst
    Sep 11 '21 at 13:58
  • $\begingroup$ @chip thanks! Curious, how did you come up with this idea? $\endgroup$ Sep 11 '21 at 15:37
  • $\begingroup$ Just happened to know the syntax. It would be nice if the boundary by default was just as smooth as what we get with RegionFunction. $\endgroup$
    – Greg Hurst
    Sep 11 '21 at 22:02

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.