4

I've been working on creating the following picture using TikZ.

enter image description here

The following code is as far as I've gotten.

\documentclass[width=5cm, height=5cm, border=2mm]{standalone}   
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]

% cartesian coordinates
\draw[-] (-2cm,0cm) -- (2cm,0cm) node[right,fill=white] {$x$};
\draw[-] (0cm,-1cm) -- (0cm,3.1cm) node[above,fill=white] {$y$};

% sine graph with shading
\draw [thick, domain=0:2*pi, samples=200, smooth] plot (xy polar cs:angle=\x r,radius= 
{1+1*sin(\x r)});
\filldraw [thick, even odd rule, fill=gray!50, fill opacity=0.3, domain=pi/6:5*pi/6, 
samples=200, smooth] plot (xy polar cs:angle=\x r,radius= {1+1*sin(\x r)}) 
(0,1.5)circle(1.5cm);

\end{tikzpicture} 
\end{document}

I was attempting with this code to first plot the sine graph(the one with a little dimple at the bottom) and then plot the shaded circle graph. The sine graph will only exist between pi/6 and 5pi/6, thus it'll "even odd rule" with the existing shaded circle and remove the shading within that region but as seen below it doesn't quite work out the way I was expecting. Pardon my limp explanation of the even odd rule, it's new to me and I'm still learning how to competently use it.

The above code produces the following polar plot.

enter image description here

How can I remove the obvious gray semicircle so it'll be like the sketch above?

Cheers in advance!

4

This solution does not use the even odd rule option, just exploits the fact that you know the intersection points

\documentclass[width=5cm, height=5cm, border=2mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]

% cartesian coordinates
\draw[-] (-2cm,0cm) -- (2cm,0cm) node[right,fill=white] {$x$};
\draw[-] (0cm,-1cm) -- (0cm,3.1cm) node[above,fill=white] {$y$};

% sine graph with shading
\fill [thick, fill=gray!50, fill opacity=0.3, domain=pi/6:5*pi/6,
samples=200, smooth] plot (xy polar cs:angle=\x r,radius= {1+1*sin(\x r)})
arc (210 : -30 : 1.5);
\draw [thick, domain=0:2*pi, samples=200, smooth] plot (xy polar cs:angle=\x r,radius=
{1+1*sin(\x r)}) (0, 1.5) circle (1.5cm);

\end{tikzpicture}
\end{document}

enter image description here

  • In hind sight a few hours after I posted this question I was thinking and realized that the even odd rule doesn't apply in this instance, like you had pointed out. It's a shame I didn't catch it earlier, but regardless thank you for your patience and response. It really does help me learn this language. Cheers – salami_pirate Dec 18 '18 at 17:35
  • @salami_pirate if you saw the issue that means you are on the right track :) – caverac Dec 18 '18 at 17:42

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.