I want to draw circular waves like these:
in TikZ.
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}
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.
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.
article
class before replacing it with standalone
. And I was thinking of pgfplots
solution earlier. Thanks for the heads up.
Commented
Nov 15, 2012 at 8:52
border=10
to the options to the standalone
class can help when the clipping is overzealous.
Commented
Nov 15, 2012 at 9:56
data cs=polar
(your example is prettier than mine in the manual)
Commented
Nov 17, 2012 at 16:39
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
\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
\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
\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).
Here is another TikZ solution...
\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}
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:
Just 4 fun with PSTricks. (and probably Bohr used PSTricks to illustrate his atomic model.)
\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}
\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}
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 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}
convert
magic line ? ;-)
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
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.