4
$\begingroup$

I've been studying the page Shading between polar graphs and there seems to be some sort of common problem with a number of the Answers. I am using Mathematica 10.2 on a MacBook Pro laptop (10.10.4). For example, when I try this code, after exiting Mathematica, starting Mathematica, and opening a new notebook:

Show[PolarPlot[{{1, -1} Sqrt[2 Cos[t]], 
   2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}], 
 RegionPlot[
  Sqrt[x^2 + y^2] > 2 (1 - Cos[ArcTan[x, y]]) && 
   Sqrt[x^2 + y^2] < Re@Sqrt[2 Cos[ArcTan[x, y]]], {x, -2, 2}, {y, -3,
    3}], PlotRange -> All]

I get this image:

enter image description here

A very similar image mistake also occurs with several other answers.

Thoughs?

Reply to Guess who it is:

I think you are talking about adding this Method.

Show[PolarPlot[{{1, -1} Sqrt[2 Cos[t]], 
   2 (1 - Cos[t])}, {t, -\[Pi], \[Pi]}], 
 RegionPlot[
  Sqrt[x^2 + y^2] > 2 (1 - Cos[ArcTan[x, y]]) && 
   Sqrt[x^2 + y^2] < Re@Sqrt[2 Cos[ArcTan[x, y]]], {x, -2, 2}, {y, -3,
    3}], PlotRange -> All,
 Method -> {"TransparentPolygonMesh" -> True}]

But note that there is still a problem.

enter image description here

So I don't think this is quite a duplicate.

The Toad asked me to post his image:

eqns[t_] := {Sqrt[2 Cos[t]], 2 (1 - Cos[t])};
region = PolarPlot[eqns[t], {t, -\[Pi], \[Pi]}, 
   RegionFunction -> 
    Function[{x, y, t, r}, {#1 > #2} & @@ Re[eqns[t]] // First]];
pts = Cases[region, Line[x___] :> x, Infinity];
colors = {Darker@Green, Blue};

Show[PolarPlot[Evaluate@eqns[t], {t, -\[Pi], \[Pi]}, 
  PlotStyle -> colors], 
 ListLinePlot[pts, PlotStyle -> colors, Filling -> Axis, 
  FillingStyle -> LightGreen], PlotRange -> All]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Have you tried that solution I showed earlier? It's the exact same problem. $\endgroup$ – J. M. will be back soon Aug 14 '15 at 18:09
  • $\begingroup$ @J. M. See my update to my original post. $\endgroup$ – David Aug 14 '15 at 18:33
  • $\begingroup$ If I understand what you are referring to as "the problem", i.e. the appearance of that straight line instead of the polar curve, you can simply Evaluate the argument of PolarPlot, which otherwise has a HoldAll attribute: PolarPlot[ Evaluate@{{1, -1} Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, Pi, Pi}] which generates this plot. Nevertheless, there is still something weird here: clearly this evaluation wasn't needed in 2012 when those questions and answers you linked to were generated. Has something changed within PolarPlot since then? $\endgroup$ – MarcoB Aug 14 '15 at 19:43
  • $\begingroup$ It would help if the question were more explicit that "Thoughs?" The main problem prima facie is the mesh, which is what the title of the question is about. The update still does not make clear what the problem is, although I think MarcoB has identified the next most likely thing. If it is the line, then the problem is simply PolarPlot[{{1, -1} Sqrt[2 Cos[t]]}, {t, -Pi, Pi}] without the other stuff to distract us. $\endgroup$ – Michael E2 Aug 14 '15 at 22:14
  • $\begingroup$ @MichaelE2 Yes, MarcoB did interpret correctly the problem after I added Guess who it is suggestion. But this is not my code. It came from the page Shading between polar graphs and there are about three answers there now that no longer work. As MarcoB said, there is something weird going on. I was just sort of trying to report it because that page is a potentially great page. $\endgroup$ – David Aug 15 '15 at 1:02
6
$\begingroup$

Basically, one should expect

PolarPlot[f1[t],...]

to plot parametrically the curve {f1[t] Cos[t], f1[t] Sin[t]}. When there is a list of more than one function {f1[t], f2[t],...}, then it should do the same for each function.

Like all the function-plotting commands PolarPlot is HoldAll. What should happen when the function call is of the following form, as it is in this case?

PolarPlot[{{-1, 1} f1[t], f2[t]},...]

Well, of course the user would like it to plot {-f1[t], f1[t], f2[t]}, flattening out the list. But in its unevaluated state, it has the form

PolarPlot[{g1[t], f2[t]},...]

As it turns out, at least in V10, from the first element is constructed

{g1[t] Cos[t], g1[t] Sin[t]}

which evaluates to two parametrizations

{ {-f1[t] Cos[t], f1[t] Cos[t]},   {-f1[t] Sin[t], f1[t] Sin[t]} }

and each of these parametrizes the same line y == -x. (At some point, the list must be parsed into two parametrizations in order to construct a plot at all. However the parsing happens, it is after the threading with Cos[t] and Sin[t] as shown above.) Note the same thing happens with the simpler command

PolarPlot[{-1, 1} Sqrt[2 Cos[t]]}, {t, -Pi, Pi}]

A proper fix would be

PolarPlot[Evaluate@Flatten@{{1, -1} Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, -Pi, Pi}]

but as pointed out in the comments, the following suffices (in the current version V10.2):

PolarPlot[Evaluate@{{1, -1} Sqrt[2 Cos[t]], 2 (1 - Cos[t])}, {t, -Pi, Pi}]
$\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.