14

I need help to plot the following Arhimede's spiral, which in polar coordinates has the equation

r=t, t\in [0,4*pi]

I used the code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{polar}

\begin{document}

\begin{figure}
 \begin{tikzpicture}
        \begin{axis}
        [xlabel=$x$,ylabel=$y$,axis lines=middle, xtick={2},ytick={2},
no marks,axis equal,xmin=-20,xmax=20,ymin=-20,ymin=20,enlargelimits={upper=0.1}]
          \addplot[no markers,samples=101, domain=0:8*pi,variable=\t]({(\t)*cos(\t r)}, {(\t)*sin(\t r)});
        \end{axis}
 \end{tikzpicture}
\end{figure}

\end{document} 

But the output is far from the desired plotting. How can I fix it ?

3
  • 2
    Just replace the second ymin=20 by ymax=20 and use samples=1001 to make it a bit smoother. – Sergei Golovan Dec 11 '17 at 8:18
  • Also, if you add in the plot \addplot[data cs=polar, ...] you can write the coordinates directly in polar coordinates. (\t r, \t), which might make it simpler as well – Alex Recuenco Dec 11 '17 at 8:46
  • @Sergei Golovan & Alex Recuenco Thank you a lot ! – Cris Dec 11 '17 at 14:51
21

You're loading the polar library, so I presume you'd like to have a polar grid.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{polar}

\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{polaraxis}
      [no marks,samples=201,smooth,domain=0:4]
      \addplot+ (4*180*x,x);
    \end{polaraxis}
  \end{tikzpicture}
\end{figure}

\end{document}

enter image description here

2
  • Thank you @Henri Menke, for this valuable work ! How can I remove the grid, if possible ? – Cris Dec 11 '17 at 14:48
  • @Cris \begin{polaraxis}[axis lines=none,... – Henri Menke Dec 11 '17 at 20:11
12

A MetaPost version of this spiral drawing, for whom it may interest. Included in a LuaLaTeX program.

Edit : inspired by Thruston's solution, I've used the dir function instead of rotated.

\RequirePackage{luatex85}
\documentclass[border=5bp]{standalone}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
    u := .25cm; Rmax := 26; eps := 1;
    beginfig(1);
        % Polar grid
        label.top("$0$", origin);
        for t = 0 step 30 until 330:
            pair radius; radius = (Rmax+eps)*u * dir t;
            draw origin -- radius withcolor .8white;
            freelabel (decimal t, radius, origin);
        endfor;
        for j = 2 step 2 until Rmax:
            r := 2j*u; draw fullcircle scaled r withcolor .8white;
        endfor;
        for j = 4 step 4 until Rmax: label.top(decimal j, (j*u, 0)); endfor;
        % Spiral
        rad := pi/180*u;
        draw (origin for t = 1 upto 1440: .. t * dir t endfor) scaled rad withcolor blue;
    endfig;
\end{mplibcode}
\end{document}

enter image description here

0
9

PSTricks can solve it without hassle. One approach is as follows. Other approaches but with the same output are given in the last section.

\documentclass[pstricks,border=1cm]{standalone}
\usepackage{pst-plot}
\psset{plotpoints=200}
\def\psvlabel#1{$\scriptstyle#1^\circ$}

\begin{document}

% r = f(Θ) in infix
\begin{pspicture}(-6,-6)(6,6)
    \psaxes[axesstyle=polar](6,0)
    \psplot[algebraic,polarplot,linecolor=red]{0}{TwoPi 2  mul}{x/3}
\end{pspicture}   

\end{document}

enter image description here

The last section: Other approaches

For documentation purposes, let me introduce other approaches to produce the same output. Other parameters are intentionally omitted for the sake of simplicity.

% x = f(t) and y = g(t), both are in infix
\begin{pspicture}(-6,-6)(6,6)
    \psaxes[axesstyle=polar](6,360)
    \psparametricplot[algebraic,linecolor=red]{0}{TwoPi 2  mul}{t/3*cos(t)|t/3*sin(t)}
\end{pspicture}

% r = f(Θ) in postfix
\begin{pspicture}(-6,-6)(6,6)
    \psaxes[axesstyle=polar](6,360)
    \psplot[polarplot,linecolor=red]{0}{360 2 mul}{x DegtoRad 3 div}
\end{pspicture}

% x = f(t) and y = g(t), both are in postfix
\begin{pspicture}(-6,-6)(6,6)
    \psaxes[axesstyle=polar](6,360)
    \psparametricplot[linecolor=red]{0}{360 2 mul}{t DegtoRad 3 div t PtoC}
\end{pspicture}

Even though domain can be specified in both radian and degree, I recommend using degree when the function is in postfix.

1
  • I intentionally changed the function from r=Θ to r=Θ/3 to minimize the required space. – Kim Jong Un Dec 11 '17 at 20:03
9

Just for comparison, here is a generic Archimedes spiral in Metapost (wrapped up here in luamplib, so compile with lualatex).

An Archimedes' Spiral with 8 turns

\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    numeric turns, radius;
    path ss;

    turns = 8;
    radius = 5cm;
    ss = (origin for t=1 upto 360 turns: -- dir t scaled t endfor) scaled (radius/turns/360);

    draw (left--right) scaled radius withcolor 1/2 white;
    draw (down--up)    scaled radius withcolor 1/2 white;

    drawarrow ss withcolor 2/3 blue;
endfig;
\end{mplibcode}
\end{document}
2
  • Should have thought myself to use dir instead of rotated – Franck Pastor Dec 11 '17 at 21:47
  • @FranckPastor, I'm sorry to have posted a second MP solution - I had not seen yours when I did. – Thruston Dec 11 '17 at 23:02

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.