2

I'm having to draw a polar graph and shade the area between the line (theta = pi/8) (blue line) and the curve (r = 4 * sqrt(2) * cos(2*theta) (red curve). Figure

My current Latex (the area hasn't been shaded)

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}[scale=10]
        
        \begin{scriptsize}
            \draw[->](0,0)--(0.5,0) node[right] {initial line};
            \draw (0.03,0.2) node[right] {$r=4\sqrt{2}\cos{2\theta}$};
            \draw (0,0.01) node[above] {$O$};
            \draw[blue] (0,0)--(0.35,0.15) node[right] {$\theta=\frac{\pi}{8}$};
            \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius=  {4*sqrt(2)*cos(2*\x r)});
            
        \end{scriptsize}
    \end{tikzpicture}
\end{document}

I want to ask how to shade the area, I searched it but could not find the solution. (I'm the beginner). Thank you in advance!

I tried to draw an area that not totally fit in the needed position by adding this line: \draw[fill=gray](0.01,0)to[out=215](0.13,0.053)--(0.06,0.028)--cycle;

sebo1234
  • 608
  • 5
  • 18

1 Answers1

2

It's very easy with \clip. The requirement is to provide closed figures, such as circle, rectangle, or the one you draw by the code. A simple \draw can also create polygons if you append cycle at the end of the definition. Incidentally, [plot] creates close figures, as well.

Below is a solution based on \clip. Some points have to be used twice, first under the "clip scope" and then in regular layer, hence I have defined and named a few coordinates. For the same reason, I created a macro that is used twiced.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{patterns.meta}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}

\begin{document}
\begin{tikzpicture}
  \path
  coordinate (E) at (0.6,4)
  coordinate (F) at (7,3)
  coordinate (P) at (3,3)
  coordinate (I) at (10,0)
  coordinate (O) at (0,0);
  \begin{scope}
    \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
    \draw[pattern={Lines[angle=135,distance={0.5mm}]}, pattern color=gray!50] (O)--(F)--(P)--cycle;   % <--- need cycle here
  \end{scope}
  \node at (O) [above=1mm] {$O$};   % nodes also accept distance for labels
  \node at (E) [right] {$r=4\sqrt{2}\cos{2\theta}$};
  \draw[blue] (O)--(F) node[right] {$\theta=\frac{\pi}{8}$};
  \draw[->,>={latex}] (O)--(I) node[right] {initial line};
  \draw[red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

enter image description here


Just for demonstration, here's how to clip a circle by your figure:

\documentclass[tikz,border=2mm]{standalone}
\newcommand\eq{80*sqrt(2)*cos(2*\x r)}
\begin{document}
\begin{tikzpicture}
    \begin{scope}
      \clip[domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
      \draw[fill=green] (0,0) circle (3);
    \end{scope}
    \draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar cs:angle=\x r,radius={\eq});
\end{tikzpicture}
\end{document}

enter image description here

Celdor
  • 2,437
  • 2
  • 23
  • 44