16

How can I draw an image like this in LaTeX? I want to show that I am drawing a circle.

enter image description here

Here is what I have, but it does not work.

\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pstricks-add}
\pstVerb
{
    /major 2.25 def
    /minor 1.75 def
    % b a t p2c ---> x y
    % where b (semi-minor), a (semi-major), t (theta)
    /p2c {dup 3 1 roll cos mul 3 1 roll sin mul} bind def
}

\psset{arrows=-*}

\begin{document}
\multido{\i=0+10}{37}
{
    \begin{pspicture}(-2.5,-2.0)(2.5,2.0)
        \ifnum\i=0
            % don't draw arc!
        \else
            \psellipticarc[linecolor=cyan,dimen=middle](!major minor){0}{(!minor major \i\space p2c)}%dimen=middle must be specified!
        \fi
        \psline[linecolor=red](!minor major \i\space p2c)
        \uput{5mm}[!\i\space 10 add](0,0){\tiny$\i^\circ$}
    \end{pspicture}
}
\end{document}
11
  • Welcome! Please note that this has nothing obviously to do with the LaTeX 3 project so I've retagged it. What do you have so far? What's the context? Is this in Beamer or another presentation package? Please provide a Minimal Working Example so that we understand the context and can see what you've got so far.
    – cfr
    Apr 9, 2016 at 11:03
  • This is not in Beamer. I know how to draw circle, lines and so on. But how can I get many frames that when I convert it to gif, it seems like that I am drawing a circle.
    – user
    Apr 9, 2016 at 11:33
  • It will help to post what you have. But Beamer is the obvious thought for multiple frames. I guess you can use any of the looping tools to get multiple pages, though.
    – cfr
    Apr 9, 2016 at 11:39
  • Here is what I have and it doesnot work.
    – user
    Apr 9, 2016 at 14:07
  • Can somebody please help?
    – user
    Apr 9, 2016 at 15:00

3 Answers 3

8

Just because I love a good challenge.

Compiled using convert -delay 10 -loop 0 -density 300 -scale 400 -alpha remove <file>.pdf <file>.gif.

Missing features/improvements:

  • red line "curving", not sure how to easily do it.
  • Some transitions should be paused more. Will try to fix later.
  • Various repeated commands might be reduced.

Output

The file is 973 KB

enter image description here

Code

254 lines! :D

\documentclass[tikz, margin=10pt]{standalone}
\usetikzlibrary{calc, arrows, backgrounds}

\newcommand\rad{57.296}
\pgfmathsetmacro\radq{\rad*2}
\pgfmathsetmacro\radc{\rad*3}

\tikzset{
    dots/.style={fill=#1, circle, inner sep=2pt},
    angle/.style={draw=green!70!black, fill=green!30},
    mainline/.style={green!70!black, very thick},
    arc/.style={red, very thick},
    rads/.style={very thin},
}

\begin{document}
\foreach \x [count=\xx, evaluate=\x as \xy using (185-\xx*5)] in {0,.5,...,4,4,4,4,4}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \node[dots=red] (a) at (0,0) {};
    \node[dots=red] (b) at (\x,0) {};
    \draw[arc] (a) -- (b);
\end{tikzpicture}
}
\foreach \ang in {0,15,...,360}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \node[dots=red] (a) at (0,0) {};
    \node[dots=red] (b) at (\ang:4) {};
    \draw[blue, thick] (4,0) arc (0:\ang:4);
    \draw[arc] (a) -- (b);

\end{tikzpicture}
}
\foreach \x [evaluate=\x as \opac using (\x/10)] in {0,0,0,1,...,9,10,10,10,10,10,10,10,9,...,0,0,0}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \node[dots=red] (a) at (0,0) {};
    \node[dots=red] (b) at (0:4) {};
    \draw[arc] (a) -- (b) node[midway, above, yshift=5mm, font=\Huge, text opacity=\opac] {r};

\end{tikzpicture}
}
\foreach \ang in {180,165,...,90}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \node[dots=black] (c) at (0,0) {};
    \node[dots=red, xshift=4cm] (a) at (\ang:4) {};
    \node[dots=red] (b) at (4,0) {};
    \draw[arc] (4,0) --++ (\ang:4);
\end{tikzpicture}
}
%\foreach \ang [count=\x, evaluate=\x as \xx using int(80/\x)] in {15,...,\rad}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \node[dots=black] (c) at (0,0) {};
    \node[dots=red] (a) at (\rad:4) {};
    \node[dots=red] (b) at (4,0) {};

    \draw[arc] (4,0) arc (0:\rad:4);
\end{tikzpicture}
%}
%
\foreach \x [evaluate=\x as \grad using (\x/10)] in {0,...,10}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \node[dots=red] (a) at (\rad:4) {};
    \node[dots=red] (b) at (4,0) {};
    \draw[arc] (4,0) arc (0:\rad:4);
    \begin{scope}[opacity=\grad]
        \draw[mainline] (b) -- (0,0) -- (a);
        \filldraw[angle] (0,0) -- (1,0) arc (0:\rad:1) -- cycle;
    \end{scope}
    \node[dots=black] (c) at (0,0) {};
\end{tikzpicture}
}
\foreach \x [evaluate=\x as \grad using (\x/10)] in {0,...,10}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \node[dots=red] (a) at (\rad:4) {};
    \node[dots=red] (b) at (4,0) {};
        \draw[arc] (4,0) arc (0:\rad:4);
        \draw[mainline] (b) -- (0,0) -- (a);
        \filldraw[angle] (0,0) -- (1,0) arc (0:\rad:1) -- cycle;
    \node[dots=black] (c) at (0,0) {};
    \begin{scope}[opacity=\grad]
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$1$ rad};
    \end{scope}
\end{tikzpicture}
}
\foreach \ang [count=\cc] in {0,10,...,\rad, \rad, \rad, \rad, \rad}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
        \draw[mainline] (4,0) arc (0:\ang:4);
        \node[dots=green!50!black] (d) at (4,0) {};
    \begin{scope}[rotate around={\ang:(0,0)}]
        \node[dots=red] (a) at (\rad:4) {};
        \node[dots=red] (b) at (4,0) {};
        \draw[arc] (4,0) arc (0:\rad:4);
        \draw[mainline] (0,0) -- (a);
        \draw[rads] (0,0) -- (b);
    \end{scope}
        \filldraw[angle] (0,0) -- (1,0) arc (0:\ang+\rad:1) -- cycle;
    \node[dots=black] (c) at (0,0) {};
    \ifnum\cc<8
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$1$ rad};
    \else
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$2$ rad};
    \fi
\end{tikzpicture}
}
\foreach \ang [count=\cc, evaluate=\ang as \bng using int(\ang+\rad)] in {0,10,...,\rad, \rad, \rad, \rad, \rad}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
        \draw[green!70!black, very thick] (4,0) arc (0:\bng:4);
        \node[dots=green!50!black] (d) at (4,0) {};
        \node[dots=green!50!black] (e) at (\rad:4) {};  
        \draw[mainline] (0,0) -- (d);
        \draw[rads] (0,0) -- (e);
    \begin{scope}[rotate around={\bng:(0,0)}]
        \node[dots=red] (a) at (\rad:4) {};
        \node[dots=red] (b) at (4,0) {};
        \draw[arc] (4,0) arc (0:\rad:4);
        \draw[mainline] (0,0) -- (a);
        \draw[rads] (0,0) -- (b);
    \end{scope}
        \filldraw[angle] (0,0) -- (1,0) arc (0:\bng+\rad:1) -- cycle;
    \node[dots=black] (c) at (0,0) {};
    \ifnum\cc<8
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$2$ rad};
    \else
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$3$ rad};
    \fi
\end{tikzpicture}
}
\foreach \dng [count=\cc, evaluate=\cc as \cng using (\radq+\rad/9*\cc)] in {\radc,...,180}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
        \draw[mainline] (4,0) arc (0:\cng:4);
        \node[dots=green!50!black] (d) at (4,0) {};
        \node[dots=green!50!black] (e) at (\rad:4) {};
        \node[dots=green!50!black] (f) at (\rad*2:4) {};
        \draw[mainline] (0,0) -- (d);
        \draw[rads] (0,0) -- (e);
        \draw[rads] (0,0) -- (f);

        \node[dots=red] (a) at (\cng:4) {};
        \node[dots=red] (b) at (\dng:4) {};
        \draw[arc] (\cng:4) arc (\cng:\dng:4);
        \draw[mainline] (0,0) -- (b);
        \draw[rads] (0,0) -- (a);
        \filldraw[angle] (0,0) -- (1,0) arc (0:\dng:1) -- cycle;
    \node[dots=black] (c) at (0,0) {};
    \ifnum\cc<9
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$3$ rad};
    \else
    \node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$\pi$ rad};
    \fi
\end{tikzpicture}
}
\foreach \x [evaluate=\x as \grad using (\x/10)] in {10,...,0,0,0,0,0,0,0,0}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \draw[mainline] (4,0) arc (0:180:4);
    \draw[mainline] (0,0) -- (d);
    \node[dots=green!50!black] (d) at (4,0) {};
    \node[dots=green!50!black] (b) at (180:4) {};
\begin{scope}[opacity=\grad]
        \node[dots=green!50!black] (e) at (\rad:4) {};
        \node[dots=green!50!black] (f) at (\rad*2:4) {};
        \draw[rads] (0,0) -- (e);
        \draw[rads] (0,0) -- (f);
        \draw[rads] (0,0) -- (a);
        \node[dots=red] (a) at (\radc:4) {};
        \node[dots=red] (b) at (180:4) {};
        \draw[arc] (\radc:4) arc (\radc:180:4);
\end{scope}
        \draw[mainline] (0,0) --++ (180:4); 
        \filldraw[angle] (0,0) -- (1,0) arc (0:180:1) -- cycle;
\node[dots=black] (c) at (0,0) {};
\node[anchor=north, yshift=-5mm, font=\Huge, text=green!50!black] at (0,0) {$\pi$ rad};
\end{tikzpicture}
}
\foreach \x in {0,5,...,20}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \draw[mainline] (4,0) arc (0:180:4);
    \node[dots=green!50!black] (d) at (4,0) {};
    \node[dots=green!50!black] (b) at (180:4) {};
    \draw[mainline] (d) -- (b);
    \filldraw[angle] (0,0) -- (1,0) arc (0:180:1) -- cycle;
\node[dots=black] (c) at (0,0) {};
\node[anchor=north, yshift=\x mm, font=\Huge, text=green!50!black] at (0,0) {$\pi$ rad};
\end{tikzpicture}
}
\foreach \ang [count=\x starting from 0, evaluate=\x as \grad using (\x/10)] in {180,198,...,360}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \draw[blue, thick] (0,0) circle (4);
    \draw[mainline] (4,0) arc (0:\ang:4);
    \node[dots=green!50!black] (d) at (4,0) {};
    \node[dots=green!50!black] (b) at (180:4) {};
    \node[dots=green!50!black] (g) at (\ang:4) {};
    \draw[mainline] (0,0) -- (d);
    \draw[mainline] (0,0) -- (g);
    \filldraw[angle] (0,0) -- (1,0) arc (0:\ang:1) -- cycle;
\node[dots=black] (c) at (0,0) {};
\node[anchor=north, yshift=2cm, font=\Huge, text=green!50!black] at (0,0) {$\pi$ rad};
\node[anchor=north, yshift=2cm, font=\Huge, text=green!50!black, text opacity=\grad] at (0,0) {$2$\phantom{$2\pi$ rad}};
\end{tikzpicture}
}
\foreach \x [evaluate=\x as \grad using (\x/10)] in {10,...,0,0}{
\begin{tikzpicture}
    \draw[gray] (-5,0) -- (5,0);
    \draw[gray] (0,-5) -- (0,5);
    \node[dots=red] (a) at (0,0) {};
\begin{scope}[opacity=\grad]
    \draw[mainline] (4,0) arc (0:360:4);
    \node[dots=green!50!black] (d) at (4,0) {};
    \node[dots=green!50!black] (b) at (180:4) {};
    \node[dots=green!50!black] (g) at (0:4) {};
    \draw[mainline] (0,0) -- (d);
    \draw[mainline] (0,0) -- (g);
    \filldraw[angle] (0,0) -- (1,0) arc (0:360:1) -- cycle;
    \node[dots=black] (c) at (0,0) {};
    \node[anchor=north, yshift=2cm, font=\Huge, text=green!50!black] at (0,0) {$\pi$ rad};
    \node[anchor=north, yshift=2cm, font=\Huge, text=green!50!black, text opacity=\grad] at (0,0) {$2$\phantom{$2\pi$ rad}};
\end{scope}
\end{tikzpicture}
}
\end{document}
0
6

That is a lot of work to get all the intermediate steps. It is much more easier to use a presentation class without the animation. Here is a starter:

\documentclass{beamer}
\usepackage{pstricks-add,multido}
\begin{document}

\begin{frame}[plain]
\centering
\def\Radius{3}
\begin{pspicture}(-4,-4)(4,4)
\psdot[dotsize=1mm,linecolor=red](0,0)\pause
\psline[arrows=*-*,linewidth=1.5pt,linecolor=red](3,0)\pause
\multido{\iA=0+30}{13}{%
  \psarc[arrows=*-*,linewidth=1.5pt,linecolor=blue](0,0){3}{0}{\iA}\pause}
\pswedge[linecolor=red,arrows=*-*,linewidth=1.5pt](3,0){3}{90}{180}\pause
\psarc[arrows=*-*,linewidth=1.5pt,linecolor=green](0,0){3}{0}{!1 RadtoDeg}
\end{pspicture}
\end{frame}

\end{document}

enter image description here

If you don't want the dots, use

    \multido{\iA=0+30}{13}{%
        \psarc[arrows=-*,linewidth=1.5pt,linecolor=white](0,0){3}{0}{!\iA\space 30 sub}
        \psarc[arrows=*-*,linewidth=1.5pt,linecolor=blue](0,0){3}{0}{\iA}\pause}

The PDF was converted into a gif by

convert -delay 50 -loop 0 -density 300 -scale 300 -alpha remove zz.pdf zz.gif

Other examples can be found here: http://tug.org/PSTricks/main.cgi?file=Animation/gif/gif

10
  • I hope you will not mind that I used your command to convert my PDF to a GIF. However, should you object, just say and I'll remove it. I had been trying to work out/remember (not sure which) how to do this with the PDF I'd produced, but was not getting very far.
    – cfr
    Apr 9, 2016 at 21:31
  • 1
    @cfr You could use arara :P
    – Alenanno
    Apr 9, 2016 at 22:00
  • @Alenanno It doesn't process a second command line when I use it. I'm not sure why. Does Arara have a convert rule for this?
    – cfr
    Apr 9, 2016 at 22:12
  • @cfr If you have arara installed and configured, add the relevant line at the very start of your .tex file, before \documentclass (for example, % arara: animate: {density: 200, delay: 50}), then open your Terminal and go to the directory where the .tex file is located, and do arara file.tex with the name of your .tex file, of course. When it says SUCCESS, you should have a file.gif in that folder.
    – Alenanno
    Apr 9, 2016 at 22:21
  • @Alenanno I know how Arara works ;). It doesn't need to be the first line, actually. But, look: I didn't know what command to use. So I couldn't very well know what to feed Arara. Moreover, Arara only reads one command line for me, at least. So I can't add another and have it be effective.
    – cfr
    Apr 9, 2016 at 22:31
3

The original code in the edited question compiled fine but produces frames for animated ellipse-drawing rather than animated circle-drawing.

Assuming that 'doesn't workrefers to the fact that the picture draws an ellipse rather than a circle, this is relatively easily fixed, even with no knowledge ofpstricks. (I say this only because I have no such knowledge and therefore disclaim allpstricks`-related responsibilities for the following i.e. if the code in the question contains obvious boo-boos, they are not going to be obvious to me.)

I started with

\begin{pspicture}(-2.5,-2.0)(2.5,2.0)

which suggested a rectangular frame, suitable for an ellipse, rather than a square one, suitable for a square. So I changed the proportions:

\begin{pspicture}(-2.5,-2.5)(2.5,2.5)

This compiled to give me an ellipse in a square frame. So I then guessed that the following lines refer to the two axes:

    /major 2.25 def
    /minor 1.75 def

and figured I'd try amending those next:

    /major 2.25 def
    /minor 2.25 def

and that did the trick - now I got 37 frames showing the drawing of a circle rather than an ellipse.

\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pstricks-add}
\pstVerb
{
    /major 2.25 def
    /minor 2.25 def
    % b a t p2c ---> x y
    % where b (semi-minor), a (semi-major), t (theta)
    /p2c {dup 3 1 roll cos mul 3 1 roll sin mul} bind def
}

\psset{arrows=-*}

\begin{document}
\multido{\i=0+10}{37}
{
    \begin{pspicture}(-2.5,-2.5)(2.5,2.5)
        \ifnum\i=0
            % don't draw arc!
        \else
            \psellipticarc[linecolor=cyan,dimen=middle](!major minor){0}{(!minor major \i\space p2c)}%dimen=middle must be specified!
        \fi
        \psline[linecolor=red](!minor major \i\space p2c)
        \uput{5mm}[!\i\space 10 add](0,0){\tiny$\i^\circ$}
    \end{pspicture}
}
\end{document}

EDIT

I was trying to figure out how to turn my PDF into an animated GIF when Herbert posted the solution in his much more expert answer. That is, using

convert -delay 50 -loop 0 -density 300 -scale 300 -alpha remove <filename>.pdf <filename>.gif 

I produced this (which I hope works - I'm not sure how to tell)

animated circle-drawing

1
  • I only get angle no blue circle. I have the same problem as my orignal question.
    – user
    Apr 9, 2016 at 21:51

You must log in to answer this question.

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