6
$\begingroup$

I'd like to reporduce this image (with shading). Color doesn't really matter.

enter image description here

Here's what I have so far

Show[
  RegionPlot[
    {2 (1 - Cos[3 ArcTan[x, y]]) > 0 && 0 > 2 (1 + Cos[3 ArcTan[x, y]])}, 
    {x, -1, 1}, {y, -1, 1},
    PlotStyle -> {Blue, Red, Green},
    PlotPoints -> 150, 
    PlotLegends -> 
      Placed[
        (ToString[#, TraditionalForm] & /@ {2 (1 - Cos[θ]) &&2 (1 + Cos[θ])}), 
        {0.75, 0.85}]], 
  PolarPlot[{2 (1 - Cos[θ]), 2 (1 + Cos[θ])}, {θ, 0, 2 Pi}], 
  PlotRange -> All,
  AspectRatio -> Automatic]

This produces traces but no fill.

$\endgroup$
6
  • 1
    $\begingroup$ A related thread. $\endgroup$ Commented Jul 31, 2017 at 3:07
  • $\begingroup$ Yea thats where I got the original code :) $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 4:19
  • 2
    $\begingroup$ Then you should have linked to it, since you used code there. :) $\endgroup$ Commented Jul 31, 2017 at 5:13
  • $\begingroup$ Will do next time. Thanks. $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 17:44
  • $\begingroup$ @Mr. Wizard. With all due respect, I cannot agree with the title change. $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 17:45

4 Answers 4

5
$\begingroup$
pp1 = ParametricPlot[Evaluate[2 {Cos[t], Sin[t]} # & /@ {1 - Cos[t], 1 + Cos[t]}], 
     {t, 0, 2 π}]

Shaded region can be obtained in two ways:

  1. Post-process a one parameter ParametricPlot constrained to an appropriate region:

For example:

sh = ParametricPlot[ConditionalExpression[{2*(1 - Cos[t + π]) {Cos[t + π], 
     Sin[t + π]}, 2*(1 + Cos[t]) {Cos[t], Sin[t]}}, π/2 <= t <= 3 π/2], {t, 0, 2 π}] /. 
     Line -> ({Red, Polygon@#} &)
  1. Using a two-parameter ParametricPlot constrained to the same region:

E.g.

sh = ParametricPlot[2 ConditionalExpression[v (1 - Cos[t + π]) {Cos[t + π], Sin[t + π]} + 
      (1 - v) (1 + Cos[t]) {Cos[t], Sin[t]}, π/2 <= t <= 3 π/2], 
    {t, 0, 2 π}, {v, 0, 1}, Mesh -> None, PlotStyle -> Directive[Opacity[1], Red]]

Then Show pp1 and sh together:

Show[pp1, sh, Frame -> True]

enter image description here

Note: In both versions, the option RegionFunction can be used instead of ConditionalExpression to constrain the plot to the desired region. That is

sh = ParametricPlot[{2*(1 - Cos[t + π]) {Cos[t + π],
       Sin[t + π]}, 2*(1 + Cos[t]) {Cos[t], Sin[t]}}, 
       {t, 0, 2 π}, 
       RegionFunction -> Function[{x, y, t, r}, π/2 <= t <= 3 π/2]] /. 
      Line -> ({Red, Polygon@#} &)

and

sh = ParametricPlot[2 v (1 - Cos[t + π]) {Cos[t + π], Sin[t + π]} + 
        2 (1 - v) (1 + Cos[t]) {Cos[t], Sin[t]}, 
        {t, 0, 2 π}, {v, 0, 1},
        RegionFunction -> Function[{x, y, t, r}, π/2 <= t <= 3 π/2],
        Mesh -> None, PlotStyle -> Directive[Opacity[1], Red]]

give the same shaded region.

$\endgroup$
5
  • $\begingroup$ You would think (hope?) that there was one technique that would cover all cases.Clearly not. Thanks so much for the help. $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 2:14
  • 2
    $\begingroup$ @jamesson, Filling in PolarPlot is a challenging problem, and I am afraid I don't know any general technique. $\endgroup$
    – kglr
    Commented Jul 31, 2017 at 2:19
  • $\begingroup$ That's why my cloud storage now contains quite a few of these =P $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 2:23
  • $\begingroup$ Would it be too much trouble if I asked you to go through " # & /@ "? Seems like a lot of useful things in a small space :). $\endgroup$
    – jamesson
    Commented Jul 31, 2017 at 17:53
  • $\begingroup$ @jamesson, thank you for the accept. The pure function 2 {Cos[t], Sin[t]} # & with a single (unnamed) argument simply multiplies that argument with 2 {Cos[t], Sin[t]}. See also Function and Slot. If you give a name to this function, say f = 2 {Cos[t], Sin[t]} # & , the expression f /@ {a, b} maps f to each element of the list {a, b}, to produce {f[a], f[b]}. See also Map. Hope this helps. $\endgroup$
    – kglr
    Commented Jul 31, 2017 at 18:06
4
$\begingroup$

It can be done in terms of the PolarPlot too. However, the kglr's shading mechanism is still needed:

p1 = PolarPlot[{2*(1 + Cos[θ]), 2*(1 - Cos[θ])}, {θ, 0, 2 π}]; 
p2 = Show[
   PolarPlot[{2*(1 - Cos[θ]), {θ, -π/2, π/2}],
   PolarPlot[{2*(1 + Cos[θ])}, {θ, π/2, 3 π/2}]}]; 
Show[p1,Graphics[{Red,Cases[p2,Line[x_]:>Polygon[x], Infinity]}],PlotRange->All]
$\endgroup$
4
  • $\begingroup$ OK, so p1 draws the whole of 2*(1+Cos[θ]), whereas p2 also draws 2*(1+Cos[θ]) from π/2 to 3π/2 just for the shading, right? $\endgroup$
    – jamesson
    Commented Aug 1, 2017 at 3:50
  • 1
    $\begingroup$ @jamesson, yes, the p2 makes outer contour of the shaded area. Then we transform the Line into the filled Polygon. $\endgroup$
    – Rom38
    Commented Aug 1, 2017 at 5:08
  • $\begingroup$ Izza typo (extraneous curlybrace round the polarplot in show) - tested and working on 10.4 $\endgroup$
    – jamesson
    Commented Aug 1, 2017 at 22:41
  • $\begingroup$ Izza typo (extraneous curlybrace round the polarplot in show) - tested and working on 10.4 $\endgroup$
    – jamesson
    Commented Aug 1, 2017 at 22:41
1
$\begingroup$
Show[
 PolarPlot[{2 (1 - Cos[θ]), 2 (1 + Cos[θ])}, {θ, 0, 2 Pi}],
 RegionPlot[
  With[{r = Sqrt[x^2 + y^2], θ = ArcTan[x, y]},
   2 (1 - Cos[θ]) > r && 2 (1 + Cos[θ]) > r
   ],
    {x, -5, 5}, {y, -5, 5}, PlotPoints -> 60
  ],
  PlotRange -> All
 ]

or

Show[
 PolarPlot[{2 (1 - Cos[θ]), 2 (1 + Cos[θ])}, {θ, 0, 2 Pi}],
 PolarPlot[Min[2 (1 - Cos[θ]), 2 (1 + Cos[θ])], {θ, 0, 2 Pi}] /. Line -> Polygon,
 PlotRange -> All
]
$\endgroup$
1
$\begingroup$

The best answer is coming - (。・`ω´・)

With[{a = {2*(1 + Cos[θ]), 2*(1 - Cos[θ])}}, 
  Show[
    PolarPlot[a, {θ, 0, 2 π}], 
    ParametricPlot[r Min[a] {Cos[θ], Sin[θ]}, {θ, 0, 2 Pi}, {r, 0, 1}], 
    PlotRange -> All
  ]
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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