I have tried FillBetween and am now trying to use intersecting segments from a post I had on a different site. I am trying to create this graph from AP Classroom. I can't get the fill correct. If anyone could help, that would be great. I have tried many different combinations of L1--R2, etc with 2-3 terms, but can't get it right. I have also read the literature, but I just don't understand it. I have included a picture of what I am trying to complete.
Code: Select all
\documentclass[border=5mm]{article}
\usepackage{tikz,asymptote,ragged2e}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{
interpret as polar/.style={
x filter/.code=\pgfmathparse{cos(rawx)*rawy},
y filter/.code=\pgfmathparse{sin(rawx)*rawy}
}
}
\begin{document}
\begin{Center}
\begin{tikzpicture}[>=Triangle]
\begin{axis}[
xtick distance=1,
ytick distance=1,
axis lines=center,
axis equal image,
enlargelimits=true,
]
\addplot[name path=A,
very thick,
domain=0:180,
samples=360,
smooth,
interpret as polar
]
(x,{1-2*cos(x)});
\addplot[name path=B,
very thick,
domain=0:360,
samples=360,
smooth,
interpret as polar
] (x,{1});
\path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);
\begin{scope}[on background layer]
\fill[blue!30, opacity=0.5, intersection segments={
of=A and B, sequence={R2 -- L2}
}] -- cycle;
\end{scope}
\node[anchor=center,label=north west:$O$] at (0,0){};
\end{axis}
\end{tikzpicture}
\end{Center}
\end{document}