39

I want to draw circular waves like these:

enter image description here

in TikZ.

2
  • 9
    Welcome to TeX.sx! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are "too localized". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help.
    – hpesoj626
    Commented Nov 14, 2012 at 23:30
  • 4
    Well to start off with, it would be helpful if you figured out the equation(s) to that represents that path you want to draw -- that is a math issue, not a TeX issue. Once you get that (perhaps in parametrized form), the I'd suggest you use pgfplots pacakge to draw it. There should be plenty of examples on this site for that. Once you make an attempt and run into a specific issue, then perhaps you can update this question showing what you attempted, and then people here could help you with a specific issue. Commented Nov 14, 2012 at 23:38

5 Answers 5

32

I'll draw the first one and you try to work on the rest. You can do this iteratively, too, I think, with some extra work.

\documentclass[tikz,border=10]{standalone}

\begin{document}

\begin{tikzpicture}[scale=3,very thick]
\draw[color=red,domain=0:6.28,samples=200,smooth] plot (canvas polar
cs:angle=\x r,radius={28-8*sin(3*\x r)});
\draw[,dashed,domain=0:6.28,samples=200,smooth] plot (canvas polar
cs:angle=\x r,radius={0.5 r});
\end{tikzpicture}

\end{document}

enter image description here

As have been said in the comment above, once you have the mathematical equation in polar coordinates, it is just a matter of some pgfplots work. To learn more about pgplots, which is built upon tikz, type texdoc pgfplots in your terminal.

Edit

This is not a pgfplots solution BTW. As have been noted by Paul Gaborit in comment, pgfplots is superfluous in the given code. I was about to go back to it since I mentioned pgfplots in my answer. I've been away for a while. Anyway, others have already provided other solutions so I will leave my answer as it is.

6
  • 1
    \usepackage{pgfplots} is superfluous... Commented Nov 15, 2012 at 0:33
  • @PaulGaborit Yeah. Removed it. I was working with article class before replacing it with standalone. And I was thinking of pgfplots solution earlier. Thanks for the heads up.
    – hpesoj626
    Commented Nov 15, 2012 at 8:52
  • Adding border=10 to the options to the standalone class can help when the clipping is overzealous. Commented Nov 15, 2012 at 9:56
  • @AndrewStacey Thanks. I will update picture tomorrow when I am on a proper computer.
    – hpesoj626
    Commented Nov 15, 2012 at 9:58
  • 2
    @hpesoj626 if you do not mind, I will "copy" something inspired by your example into the pgfplots manual as an example for how to provide polar coordinates into a cartesian axis using data cs=polar (your example is prettier than mine in the manual) Commented Nov 17, 2012 at 16:39
38

The hardest part is to parametrize the curve. There are lots of ways to do this, one such way is

x(t) = (2+.5*cos(nt))cos(t)
y(t) = (2+.5*cos(nt))sin(t)

where 0\leq t\leq 2\pi and n\in \{3, 4, 5, ....\}

If you vary the .5 it will vary the sharpness of the curve.

Once you have this, you can plot the curve easily using pgfplots and its \addplot command

enter image description here

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[axis equal,axis lines=none]
 \addplot[samples=100,domain=0:2*pi,thick] ({(2+.5*cos(deg(5*x)))*cos(deg(x))},{(2+.5*cos(deg(5*x)))*sin(deg(x))});
 \addplot[samples=50,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
 \end{axis}
\end{tikzpicture}

\end{document}

Animation: vary n

vary n

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}

\foreach \n in{3,4,...,10}{%
\begin{tikzpicture}
 \begin{axis}[axis equal,
    xmin=-3,xmax=3,
    ymin=-3,ymax=3,
    axis lines=none]
 \addplot[samples=400,domain=0:2*pi,thick] ({(2+.3*cos(deg(\n*x)))*cos(deg(x))},{(2+.3*cos(deg(\n*x)))*sin(deg(x))});
 \addplot[samples=40,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
 \node at (axis cs:0,0){$n=\n$};
 \end{axis}
\end{tikzpicture}
}

\end{document}

Animation: vary 'sharpness' of the curve

animate1

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}

\foreach \r in{0.1,0.2,...,1}{%
\begin{tikzpicture}
 \begin{axis}[axis equal,
    xmin=-3,xmax=3,
    ymin=-3,ymax=3,
    axis lines=none]
 \addplot[samples=300,domain=0:2*pi,thick] ({(2+\r*cos(deg(5*x)))*cos(deg(x))},{(2+\r*cos(deg(5*x)))*sin(deg(x))});
 \addplot[samples=40,domain=0:2*pi,dashed] ({2*cos(deg(x))},{2*sin(deg(x))});
 \node at (axis cs:0,0){$r=\r$};
 \end{axis}
\end{tikzpicture}
}

\end{document}

See How to convert pstricks animation to GIF file? for full details of the rest of the animation creation process (just a couple of steps).

1
  • 4
    GarbageCollector has a rival, I see! Commented Nov 15, 2012 at 9:43
14

Here is another TikZ solution...

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \def\r{1cm}
  \def\v{2.5mm}
  \foreach \n in {3,4,5,6}{
    \begin{scope}[xshift=\n*2*(\r+\v+1mm)]
      \draw[thick]  (0:{\r+\v})
      \foreach \a in {1,...,359}{ -- (\a:{\r+cos(\a*\n)*\v}) } -- cycle;
      \draw[dashed] circle (\r);
    \end{scope}
  }
\end{tikzpicture}
\end{document}
9

If you're not too bothered about the exact equation, here's a method using the hobby package (although you'd need the development version for it to work with foreach, it's nearly ready for upload to CTAN - just needs documentation - but for now it can be found at TeX-SX Launchpad, download hobby.dtx and run tex hobby.dtx).

\documentclass{article}
%\url{http://tex.stackexchange.com/q/82773/86}
\usepackage{tikz}
\usetikzlibrary{hobby}

\begin{document}
\begin{tikzpicture}
\draw[dashed]
    (0,0) circle[radius=3cm];
\def\n{8}
\def\amp{1}
\draw[use Hobby shortcut] ([closed]3-\amp,0) \foreach \k in {1,...,\n}
{ .. (\k*360/\n:{3+(Mod(\k,2) == 1 ? \amp : -\amp)})};
\end{tikzpicture}
\end{document}

Two obvious parameters: \n is twice the number of "lumps" and \amp is the (half) amplitude.

I don't know how to do fancy animations, so here's a static image:

bumpy circles with hobby

7

Just 4 fun with PSTricks. (and probably Bohr used PSTricks to illustrate his atomic model.)

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\psset
{
    unit=\psrunit,
    polarplot,
    algebraic=true,
    plotpoints=150,
}

\begin{document}
\begin{pspicture}(-3,-3)(3,3)
\pscircle[linestyle=dashed](0,0){2}
\psplot[linecolor=red]{0}{TwoPi}{2+.5*sin(3*x)}
\end{pspicture}
\end{document}

Animated version:

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\psset
{
    unit=\psrunit,
    polarplot,
    algebraic=true,
    plotpoints=1000,
}

\begin{document}
\multido{\i=2+1}{25}{%
\begin{pspicture}(-3,-3)(3,3)
\pscircle[linestyle=dashed](0,0){2}
\psplot[linecolor=red]{0}{TwoPi}{2+.5*sin(\i*x)}
\end{pspicture}}
\end{document}

Edit:

I am a bit lazy to redo my work above. Please try cos instead of sin if you want to shift the curve period/4 along the angular direction.

The last edit:

The requested random magic by Doctor Kumar is given as follow. Please compile with pdflatex -shell-escape bohring.

% the filename of this code is bohring (not boring!)
\documentclass[preview,border=12pt]{standalone}
\usepackage{filecontents}
\def\filename{Bohr}

\begin{filecontents*}{\filename}
\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\psset
{
    unit=\psrunit,
    polarplot,
    algebraic=true,
    plotpoints=1000,
}

\begin{document}
\multido{\i=1+1}{25}{%
\begin{pspicture}(-3,-3)(3,3)
\pscircle[linestyle=dashed](0,0){2}
\psplot[linecolor=red]{0}{TwoPi}{2+.5*cos(\i*x)}
\end{pspicture}}
\end{document}
\end{filecontents*}


\usepackage{animate}

\immediate\write18{latex \filename}
\immediate\write18{dvips \filename}
\immediate\write18{ps2pdf \filename.ps}

% begin cleaning
% The following codes are written with Windows' shell commands only for Windows user.
% If you use Linux, then ask other people to translate the codes to Linux's equivalent. 
% If you have no friend who can help you, just comment the code and manually remove the associated files.
\makeatletter
\@for\x:={tex,dvi,ps,log,aux}\do{\immediate\write18{cmd /c del \filename.\x}}
\makeatother
% end cleaning

\begin{document}
\animategraphics[controls,loop,autoplay,scale=1]{2}{\filename}{}{}
\end{document}
4
  • Why the code doesn't contain convert magic line ? ;-)
    – user11232
    Commented Nov 18, 2012 at 0:40
  • @HarishKumar: Can you remove the preview environment sandwiching the animategraphics as standalone does it by default? I am limited by the system so I can have 5 edits a day. Commented Apr 25, 2013 at 12:09
  • Done. Is it OK?
    – user11232
    Commented Apr 25, 2013 at 22:44
  • @HarishKumar: Thank you very much. It suits my intent. Commented Apr 26, 2013 at 5:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .