35

enter image description here

i am trying to imitate the GIF Above but i am struggling to make a line to bend to the outer circle like in GIF.

\documentclass[tikz]{standalone}
\usepackage{tikz}

\usetikzlibrary{intersections}

\begin{document}
\foreach \x  in {0,0.1,...,1.1}
{
 \begin{tikzpicture}[scale=3]
 \draw (0,0) circle (1);
 \draw (-2.5,0)--(2.5,0); 
 \draw (0,-1.5)--(0,1.5);   
 \draw [red,very thick] (0,0)--(\x,0);      
 \end{tikzpicture}      
}

\foreach \angle  in {180,170,...,90}{
 \begin{tikzpicture}[scale=3]
 \draw (0,0) circle (1cm);
 \draw (-2.5,0)--(2.5,0); 
 \draw (0,-1.5)--(0,1.5);   
 \draw [red,very thick] (0,0)--(1,0);   
 \draw [red,very thick,xshift=1cm] (0,0) --(\angle:1);          
\end{tikzpicture}
}



 \foreach \angle in {0,10,20,30,40,50,57.35}
 {
\begin{tikzpicture}[scale=3]
\draw (0,0) circle (1cm);
\draw (-2.5,0)--(2.5,0); 
\draw (0,-1.5)--(0,1.5);    

\draw [red,very thick,xshift=1cm] (0,0) --(90:1);
\filldraw [yellow!80](60:1) circle(0.02);
\draw[blue!80,very thick] (1cm,0)
arc [start angle=0, end angle=57.35, radius=1cm];
\filldraw [red!80](57.35:1) circle(0.02);
\filldraw [red!80](0:1) circle(0.02);   

\draw[blue!80,very thick] (0,0) -- (\angle+57.35:1);

\draw[blue!80,very thick] (0,0) -- (\angle:1)
arc [start angle=\angle, end angle=\angle + 57.35, radius=1cm];
\filldraw [red!80](\angle:1) circle(0.02);
\filldraw [red!80](\angle+57.35:1) circle(0.02);    
\end{tikzpicture}
 }

\end{document}

here what i have done so far. i am able to find the coordinate to where the line should bend, which is the angle by manual calculation.

enter image description here

4
  • 1
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Jul 26, 2018 at 12:12
  • Oh Okay, sorry i'll edit this post. thank for the advice
    – k Arya
    Jul 26, 2018 at 12:15
  • it's a bit annoying how you have to watch from t=2s to t=2.5s on a gif that is 20s long to understand the question. If you missed it, you have to wait the entire loop to see it again (of course, the times are estimates)
    – Jasper
    Jul 26, 2018 at 15:09
  • ah that is a good point. how about increase time delay.
    – k Arya
    Jul 26, 2018 at 15:15

3 Answers 3

36

Basically you want to draw a part of a circle/ellipse with specific dimensions. This is called an arc.


The first try—straight forward solution with adjustment

\documentclass[tikz]{standalone}
\usepackage{tikz}

\usetikzlibrary{intersections}

\begin{document}
\foreach \k  in {0,0.1,...,1.001}{
  \begin{tikzpicture}[scale=3]
  \draw [white, fill] (-2.5,-1.5) rectangle (2.5,1.5);% you probably don't need this, depending on gif creation. I just needed it for properly creating a gif with white background.
  \draw (0,0) circle (1cm);
  \draw (-2.5,0)--(2.5,0); 
  \draw (0,-1.5)--(0,1.5);   
  \draw [red,very thick] (0,0)--(1,0);
  \draw [red,very thick,xshift=1cm] (0,0) arc (0:1r:\k\space and 1.1884-0.1884*\k);
  \end{tikzpicture}
}
\end{document}

result

This draws an arc of an ellipse and changes the dimension of the ellipse it belongs to from width 0 to a proper circle. This doesn't yield the correct height for the starting and intermediate lines. To fix this quickly and dirty, I introduced a little workaround:

The height (y value of the highest point) of the arc is sin(1). But it should be 1 in case of the straight line and decrease to sin(1). So I stretch the height accordingly in the beginning and interpolate linearly. The number 1.1884 is actually sin(1)^-1 to correct the arc length.

You could, of course, do some maths instead.


A correct way

To get the 'correct' line without a dirty trick like the above, you could use the following:

\documentclass[tikz]{standalone}
\usepackage{tikz}

\usetikzlibrary{intersections}
\def\zero{0}

\begin{document}
\foreach \k  in {0,0.1,...,1.001}{
  \begin{tikzpicture}[scale=3]
  \draw [white, fill] (-2.5,-1.5) rectangle (2.5,1.5);% you probably don't need this, depending on gif creation. I just needed it for properly creating a gif with white background.
  \draw (0,0) circle (1cm);
  \draw (-2.5,0)--(2.5,0); 
  \draw (0,-1.5)--(0,1.5);   
  \draw [red,very thick] (0,0)--(1,0);
  \ifx\k\zero
    \draw [red,very thick] (1,0)--(1,1);
  \else
    \draw[domain=0:\k r,smooth,variable=\t,red, very thick, xshift=1cm]  plot ({1/\k*cos(\t)-1/\k},{1/\k*sin(\t)});
  \fi
  \end{tikzpicture}
}
\end{document}

result2

This plot produces lines of exact length 1 with curvature \k. I used a parametric plot here, rather than the inbuilt arc from tikz.


Annotation

To produce these animations, I used ImageMagick:

convert -delay 10 -loop 0 -background white -alpha remove the.pdf result.gif

A smoother version can be created using, e.g.,

\foreach \k  in {0,0.04,...,1.001}{

instead of the other \foreach line. To fine-tune the according animation (and make it slightly larger):

convert -density 100 -loop 0 -background white -alpha remove -delay 100 the.pdf\[0\] -delay 4 the.pdf\[1-24\] -delay 100 the.pdf\[25\] result.gif

result

Here, I selected manually the delays (in hundredths of seconds) for the different page ranges, starting from zero 0, by adding \[page\] after the pdf file name. The initial and the last picture should be shown for 1 second, everything in between for 4/100 s.

Note: Depending on your shell, you might not need to escape the square brackets, i.e., use the.pdf[..] instead of the.pdf\[..\]. Thanks to @AndréC for mentioning.

Note: Although the -background white -alpha remove should work without a white rectangle as background in the pictures, it doesn't seem to work well all the time. So I added the rectangles in the code again.

6
  • @kArya see my explanation above and second approach which is more exact ;)
    – nox
    Jul 26, 2018 at 15:18
  • Very nice job ! How do you post an animated image?
    – AndréC
    Jul 26, 2018 at 17:59
  • 1
    @AndréC Thanks! You have to create a gif image, as this format allows animation. I'd suggest ImageMagick: convert -delay 10 -loop 0 -background white -alpha remove -density 100 your.pdf animated.gif, but there are other possibilities. I am not used to do it, this was my first animation as well, so I don't know a better way, maybe worth a question?
    – nox
    Jul 26, 2018 at 19:54
  • 1
    @AndréC I overhauled the answer and included some details about the animation and added an improved animation in the end :)
    – nox
    Jul 26, 2018 at 21:43
  • 1
    That's it, under windows, the selection of the pdf pages is done without slash. We must simply write this: the.pdf[0]
    – AndréC
    Jul 29, 2018 at 17:30
18

just for fun, a code that allows to complete the initial animation, based of course on the excellent codes shown, in the same way I used Imagemagick to generate the output in gif; the original file has 113 frames @ 105Kb, the code generates 110 frames @ 648Kb, this may vary with the imagemagic settings; however, the original has some frames with specific delays, and the way to declare them with imagemagick is very tedious, especially for my that use arara to compile, so I used another program (fireworks) that allows me to edit the delays in a graphic interface, the file exported is automatically compressed to 176Kb.

RAW RESULT: enter image description here

DELAY EDITED: enter image description here MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
% arara: animate: {density: 200, delay: 5, other: -background white -alpha remove}
% arara: showanimate
\documentclass[tikz,border=10pt]{standalone}
\usepackage{mathptmx} 
\definecolor{mygreen}{HTML}{019A01}
\usetikzlibrary{calc,arrows.meta}

\begin{document}
\begin{tikzpicture}[scale=2]% The initial frame 
    \path[draw,thick,gray!50] (0,0)
        edge (0:2)
        edge (90:1.2)
        edge (180:2)
        edge (270:1.2);
\end{tikzpicture}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Radio 0 to 1 increment
\begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[red,thick] (0,0) -- (\x,0) coordinate (A);
    \fill[red](0,0) circle (1pt);
    \fill[red](A) circle (1pt);
\end{tikzpicture}   
}

\foreach \x  in {0,0.02,0.05,0.1,0.2,...,0.9,0.95,0.98,1}{% Draw the blue circle r=1
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360*\x:1);
    \draw[red,thick] (0,0) -- (360*\x:1) coordinate (A);
    \fill[red](0,0) circle (1pt);
    \fill[red](A) circle (1pt);
    \end{tikzpicture}   
}
\foreach \x  in {0,0.2,1,0.2}{% Show the radious label fading 
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \fill[red](0,0) circle (1pt);
    \fill[red](1,0) circle (1pt);
    \draw[red,thick,text opacity=\x] (0,0) -- (0:1) node[midway,anchor=south,font=\Huge]{r};
    \end{tikzpicture}   
}

\foreach \x  in {0,0.02,0.05,0.1,0.2,...,0.9,0.95,0.98,1}{%Rotate Radio from (1,0)
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \fill(0,0) circle (1pt);
    \fill[red](1,0) circle (1pt);
    \draw[red,thick] (1,0) -- ++(180-90*\x:1)coordinate (A);
    \fill[red](A) circle (1pt);
    \end{tikzpicture}   
}

\foreach \x  in {0,0.02,0.05,0.1,0.2,...,0.9,0.95,0.98,1}{%Nice bending @Nox trick
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \fill(0,0) circle (1pt);
    \fill[red](1,0) circle (1pt);
    \draw [red,xshift=1cm,thick] (0,0) arc (0:180/pi:\x\space and 1.1884-0.1884*\x) node[circle,fill,inner sep=1pt]{} circle (1pt);
    \end{tikzpicture}   
}
\foreach \x  in {0.1,0.2}{%Show 1 rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[red,thick](0:1) coordinate (A) arc (0:180/pi:1) coordinate (B);
    \draw[mygreen,fill,fill opacity=0.2*\x,draw opacity=\x](0,0)
        -- (0:0.2) arc (0:180/pi:0.2) -- cycle;
    \draw[mygreen,opacity=\x,thick] (0,0) edge(A) edge(B);
    \fill[red](A) circle (1pt);
    \fill[red](B) circle (1pt);
    \fill(0,0) circle (1pt);

    \end{tikzpicture}   
}

\foreach \x  in {0,0.2,1}{%Show text 1 rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[red,thick](0:1) coordinate (A) arc (0:180/pi:1) coordinate (B);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:180/pi:0.2) -- cycle;
    \draw[mygreen,opacity=1,thick] (0,0) edge(A) edge(B);
    \fill[red](A) circle (1pt);
    \fill[red](B) circle (1pt);
    \fill(0,0) circle (1pt);
    \draw node[mygreen,font=\LARGE,opacity=\x] at (0,-0.2){\bf 1 rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Show 1 rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:180/pi*\x:1);
    \draw[red,thick](180/pi*\x:1) coordinate (A) arc (180/pi*\x:180/pi+180/pi*\x:1) coordinate (B);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:180/pi+180/pi*\x:0.2) -- cycle;
    \draw[mygreen,opacity=1,thin] (0,0) -- (A);
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(B);
    \fill[red](A) circle (1pt);
    \fill[red](B) circle (1pt);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \draw node[mygreen,font=\LARGE,opacity=1-\x] at (0,-0.2){\bf 1 rad};
    \draw node[mygreen,font=\LARGE,opacity=\x] at (0,-0.2){\bf 2 rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Show 2 rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:180/pi+180/pi*\x:1);
    \draw[red,thick](180/pi+180/pi*\x:1) coordinate (A) arc (180/pi+180/pi*\x:360/pi+180/pi*\x:1) coordinate (B);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:360/pi+180/pi*\x:0.2) -- cycle;
    \draw[mygreen,opacity=1,thin] (0,0) edge (A) edge(180/pi:1);
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(B);
    \fill[red](A) circle (1pt);
    \fill[red](B) circle (1pt);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \fill[mygreen](180/pi:1) circle (0.75pt);
    \draw node[mygreen,font=\LARGE,opacity=1-\x] at (0,-0.2){\bf 2 rad};
    \draw node[mygreen,font=\LARGE,opacity=\x] at (0,-0.2){\bf 3 rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Show 3 rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:360/pi+180*\x-360/pi*\x:1);
    \draw[red,thick]
        (360/pi+180/pi*\x:1) coordinate (A) 
        arc (360/pi+180/pi*\x:360/pi+180/pi*\x+180*\x+180/pi-720/pi*\x:1) coordinate (B);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:360/pi+180/pi*\x:0.2) -- cycle;
    \draw[mygreen,opacity=1,thin] (0,0) edge (A) edge(180/pi:1) edge(360/pi:1);
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(B);
    \fill[red](A) circle (1pt);
    \fill[red](B) circle (1pt);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \fill[mygreen](180/pi:1) circle (0.75pt);
    \fill[mygreen](360/pi:1) circle (0.75pt);
    \draw node[mygreen,font=\LARGE,opacity=1-\x] at (0,-0.2){\bf 3 rad};
        \draw node[mygreen,font=\LARGE,opacity=\x] at (0,-0.2){\bf $\mathbf{\pi}$ rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.4,0.8,1}{%Disapear lines
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:180:1);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:180:0.2) -- cycle;
    \draw[mygreen,opacity=1-\x,thin] (0,0) edge(180/pi:1) edge(360/pi:1) edge(540/pi:1);
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(-1,0);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \fill[mygreen,opacity=1-\x](180/pi:1) circle (0.75pt);
    \fill[mygreen,opacity=1-\x](360/pi:1) circle (0.75pt);
    \fill[mygreen,opacity=1-\x](540/pi:1) circle (0.75pt);
    \fill[mygreen](-1,0) circle (1pt);
    \draw node[mygreen,font=\LARGE,opacity=1] at (0,-0.2){\bf $\mathbf{\pi}$ rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Show move pi rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:180:1);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:180:0.2) -- cycle;
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(-1,0);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \fill[mygreen](-1,0) circle (1pt);
    \draw node[mygreen,font=\LARGE] at (0,0.7*\x-0.2){\bf $\mathbf{\pi}$ rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.05 ,0.1 ,0.25 ,0.4 ,0.6,0.7,0.8,0.95}{%Show  2 pi rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:180+180*\x:1) coordinate (a);
    \draw[mygreen,fill,fill opacity=0.2,draw opacity=1](0,0)
    -- (0:0.2) arc (0:180+180*\x:0.2) -- cycle;
    \draw[mygreen,opacity=1,thick] (0,0) edge(1,0) edge(-1,0) edge(a);
    \fill(0,0) circle (1pt);
    \fill[mygreen](1,0) circle (1pt);
    \fill[mygreen](a) circle (1pt);
    \fill[mygreen](-1,0) circle (0.75pt);
    \draw node[mygreen,font=\LARGE,opacity=1-\x] at (0,0.5){\bf $\mathbf{\pi}$ rad};
    \draw node[mygreen,font=\LARGE,opacity=\x] at (0,0.5){\bf $\mathbf{2\pi}$ rad};
    \end{tikzpicture}   
}
\foreach \x  in {0.4,0.6,0.8,1}{%Show  2 pi rad
    \begin{tikzpicture}[scale=2]
    \path[draw,thick,gray!50] (0,0)
    edge (0:2)
    edge (90:1.2)
    edge (180:2)
    edge (270:1.2);
    \draw[blue] (0:1) arc (0:360:1);
    \draw[mygreen,thick] (0:1) arc (0:360:1) coordinate (a);
    \draw[mygreen,fill,fill opacity=0.2-0.2*\x,draw opacity=1-\x](0,0)
    -- (0:0.2) arc (0:360:0.2) -- cycle;
    \draw[mygreen,opacity=1-\x,thick] (0,0) edge(1,0) edge(-1,0) edge(a);
    \fill(0,0) circle (1pt);
    \fill[mygreen,opacity=1-\x](1,0) circle (1pt);
    \fill[mygreen,opacity=1-\x](a) circle (1pt);
    \fill[mygreen,opacity=1-\x](-1,0) circle (0.75pt);
    \draw node[mygreen,font=\LARGE] at (0,0.5){\bf $\mathbf{2\pi}$ rad};
    \end{tikzpicture}   
}
\end{document}
2
  • @ J Leon wow great, thanks. Is it using adobe firework to edit animation ?
    – k Arya
    Jul 29, 2018 at 4:35
  • Yes, only to edit the delay of certain frames and analyze the number of frames and the delay that the original gif image have.
    – J Leon V.
    Jul 29, 2018 at 5:06
18

Based on the nice answer from nox, this is a version which only draws segments of circles instead of ellipses: It uses pgfmath to determine the radius of circle segments with arc length 1 starting at (1,0) with varying angles.

\documentclass[tikz]{standalone}
\usepackage{tikz,ifthen}

\begin{document}
\foreach \x  in {0,0.05,...,1.001}{
    \begin{tikzpicture}[scale=3]
    \draw [white, fill] (-2.5,-1.5) rectangle (2.5,1.5);% you probably don't need this, I just needed it for properly creating a gif with white background
    \draw (0,0) circle (1cm);
    \draw (-2.5,0)--(2.5,0); 
    \draw (0,-1.5)--(0,1.5);   
    \draw [red,very thick] (0,0)--(1,0);
    \ifthenelse{\equal\x0}{
      \draw [red,very thick] (1,0)--(1,1);
    }{
      \draw [red,very thick,xshift=1cm] (0,0) arc (0:deg(\x):1/\x);
    }
    \end{tikzpicture}
}
\end{document}

enter image description here

2
  • Nice and clean :)
    – nox
    Jul 26, 2018 at 22:14
  • @Marcel thanks for another nice solution :)
    – k Arya
    Jul 29, 2018 at 4:34

You must log in to answer this question.

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