# How can I fill the region where two polar plots intersect?

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

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.

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

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]


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.

• You would think (hope?) that there was one technique that would cover all cases.Clearly not. Thanks so much for the help. – jamesson Jul 31 '17 at 2:14
• @jamesson, Filling in PolarPlot is a challenging problem, and I am afraid I don't know any general technique. – kglr Jul 31 '17 at 2:19
• That's why my cloud storage now contains quite a few of these =P – jamesson Jul 31 '17 at 2:23
• Would it be too much trouble if I asked you to go through " # & /@ "? Seems like a lot of useful things in a small space :). – jamesson Jul 31 '17 at 17:53
• @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. – kglr Jul 31 '17 at 18:06

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]

• 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? – jamesson Aug 1 '17 at 3:50
• @jamesson, yes, the p2 makes outer contour of the shaded area. Then we transform the Line into the filled Polygon. – Rom38 Aug 1 '17 at 5:08
• Izza typo (extraneous curlybrace round the polarplot in show) - tested and working on 10.4 – jamesson Aug 1 '17 at 22:41
• Izza typo (extraneous curlybrace round the polarplot in show) - tested and working on 10.4 – jamesson Aug 1 '17 at 22:41
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
]


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
]
]
`