[Tex/LaTex] tikz and polar plot

tikz-pgf

I am completely lost with this problem : I want to plot some polar curve. Here is something that works :

\begin{center}
  \begin{tikzpicture}[xscale=1,yscale=1]
  \draw[thick,->,>=latex] (-2,0)--(2.5,0) node[above] {$x$};
  \draw[thick,->,>=latex] (0,-2)--(0,2) node[left] {$y$};
  \draw[domain=0:540,scale=1.5,samples=500] plot (\x:{cos(\x/3)*cos(\x/3)*cos(\x/3)});
  \end{tikzpicture}
  \end{center}

But if I do almost the same, namely :

\begin{center}
  \begin{tikzpicture}[xscale=1,yscale=1]
  \draw[thick,->,>=latex] (-2,0)--(2.5,0) node[above] {$x$};
  \draw[thick,->,>=latex] (0,-2)--(0,2) node[left] {$y$};
  \draw[domain=0:3*pi,scale=1.5,samples=500] plot (\x:{cos(\x/3 r)*cos(\x/3 r)*cos(\x/3 r)});
  \end{tikzpicture}
  \end{center}

or even :

\begin{center}
  \begin{tikzpicture}[xscale=1,yscale=1]
  \draw[thick,->,>=latex] (-2,0)--(2.5,0) node[above] {$x$};
  \draw[thick,->,>=latex] (0,-2)--(0,2) node[left] {$y$};
  \draw[domain=0:3*pi,scale=1.5,samples=500] plot (\x:{cos(\x/3*180/pi)*cos(\x/3*180/pi)*cos(\x/3*180/pi)});
  \end{tikzpicture}
  \end{center}

the last two don't work. I have no clue why Tikz cannot accepet the radian with the previous two.

Also, if anyone can tell me how to avoid to write three times the cosine to make it as cube, that'd be great. I tried several syntaxes, but none of them worked.

What is for me very strange is that I ploted some polar curve before, and for example this syntax worked fine :

\begin{center}
\begin{tikzpicture}[xscale=0.5,yscale=30]
\fill[pattern=north east lines]
  plot [domain=-pi/4:0,scale=3,samples=500] (\x:{-2*cos(2*\x r)/cos(\x r)})%
 -- plot [domain=0:pi/4,scale=3,samples=500] (\x:{-2*cos(2*\x r)/cos(\x r)})%
 -- cycle ;
\draw[thick,->,>=latex] (-8,0)--(8,0) node[above] {$x$};
\draw[thick,->,>=latex] (0,-0.05)--(0,0.15) node[left] {$y$};
\draw[thick,dotted] (6,-0.12)--(6,0.13);
\draw (-6,0) node[below left] {$-a$};
\draw (6,0) node[below right] {$a$};
\draw[domain=-pi/2.4:pi/2.3,scale=3,samples=500] plot (\x:{-2*cos(2*\x r)/cos(\x r)});
\end{tikzpicture}
\end{center}

I would appreciate any comment !

Best Answer

When using polar coordinates the angle is a value in degrees, but you supply an angle in radians. Use {deg(\x)} to convert \x to degrees. For the cube you can use cos(\x r)^3.

enter image description here

\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[thick,->,>=latex] (-2,0)--(2.5,0) node[above] {$x$};
  \draw[thick,->,>=latex] (0,-2)--(0,2) node[left] {$y$};
  \draw[domain=0:540,scale=1.5,samples=500] plot (\x:{cos(\x/3)^3});
\end{tikzpicture}

\begin{tikzpicture}
  \draw[thick,->,>=latex] (-2,0)--(2.5,0) node[above] {$x$};
  \draw[thick,->,>=latex] (0,-2)--(0,2) node[left] {$y$};
  \draw[domain=0:3*pi,scale=1.5,samples=500] plot ({deg(\x)}:{cos(\x/3 r)^3});
\end{tikzpicture}

\end{document}