# How do I draw a circle and shade an area?

This is the problem.

A circular corral of unit radius is enclosed by a fence. A goat inside the corral is tied to the fence with a rope of length $0 \le a \le 2$ (see figure). What is the area of the region (inside the corral) that the goat can graze? Check your answer with the special cases $a=0$ and $a=2$.

See figure:

This is what I have so far.

I figured that I can't do filling with PolarPlot and I wonder what are the alternative ways of showing the problem in Mathematica.

I think ultimately I will need something that look like this: (Blue is the shaded part)

• A related question. Commented Aug 30, 2017 at 4:08
• Possible duplicate: 104919, (which is itself a duplicate of 66234, but is more closely related to this one) Commented Aug 30, 2017 at 6:26

Try this:

d1 = Disk[{0, 0}, 1];
d2 = Disk[{0, 1}, 1];
d3 = RegionIntersection[d1, d2];
Show[{
Graphics[{White, EdgeForm[Directive[Red, Thick]], d2}],
RegionPlot[d3, PlotStyle -> Blue, BoundaryStyle -> {Red, Thick}]
}]


Have fun!

Here's a tasty one-liner solution for the computational part of the problem!

Simplify@Integrate[1, {x, y} \[Element] RegionIntersection[Disk[], Disk[{1, 0}, a]], GenerateConditions -> True]


Using Manipulate allows you to easily vary the radius. You could do all your plotting with RegionPlot, but I found this way gave higher quality plots more easily.

Manipulate[
regint = RegionIntersection[Disk[{0, 0}, 1], Disk[{0, 1}, a]];
Show[Graphics[{EdgeForm[Directive[Thick, Black]], LightBlue,
Disk[{0, 0}, 1]}],
Graphics[{EdgeForm[Directive[Black, Dashed]], LightGreen,
Disk[{0, 1}, a]}],
RegionPlot[regint, BoundaryStyle -> Directive[Red, Thick],
PlotStyle -> Blue], PlotRange -> {{-2, 2}, {-1, 3}},
PlotLabel -> "Area = " <> ToString[RegionMeasure@regint]],
{{a, Sqrt[2]}, 0, 2}]


reg[a_] := RegionIntersection[Disk[], Disk[{0, 1}, a]]
rp[a_] :=
With[{region = reg[a]},
RegionPlot[region,
Epilog -> {Red, PointSize[0.02], Point[{0, 1}], Black, Circle[],
Text[Style[Area@region, 20, Bold], {0, 0}]},
PlotRange -> Table[{-1, 1}, 2]]]
tab = Table[rp[a], {a, 0.1, 2, 0.1}];


The table exported as an animated gif:

The area can determined as above using Area on Region or you can calculate yourself,e.g. the sum of the orange and black areas:

For example (I did not "deal with a=0"):

int[a_] := {x, y} /.
NSolve[{x^2 + y^2 == 1, x^2 + (y - 1)^2 == a^2}, {x, y}, Reals]
ar1[a_] := VectorAngle @@ ({#1, #2 - 1} & @@@ int[a]) a^2/2
ar2[a_] := Module[{i = int[a], v},
v = VectorAngle[i[[1]], {0, 1}];
v - Norm[i[[1]] - {0, 1}] Cos[v/2]]
aint[a_] := ar1[a] + ar2[a]
Table[{j, Area@reg[j], aint[j]}, {j, 0.1, 2, 0.1}] //
TableForm[#, TableHeadings -> {None, {"a", "Method 1", "Method 2"}}] &