How do I bend a line onto a circle?
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}
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}
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
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.
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}
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:
DELAY EDITED: 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}