我正在尝试模仿上面的 GIF,但我很难让线像 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}
这是我目前所做的。我能够找到线应该弯曲的坐标,即通过手动计算的角度。
答案1
基本上,你想画出具有特定尺寸的圆或椭圆的一部分。这被称为圆弧。
第一次尝试——直接调整解决方案
\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}
这将绘制一个椭圆的圆弧,并将其所属的椭圆的尺寸从宽度更改0
为正确的圆形。这不会产生起始线和中间线的正确高度。为了快速解决这个问题,我引入了一个小小的解决方法:
圆弧的高度(最高点的 y 值)为。但如果是直线,sin(1)
则应为,并减小到。因此,我在开始时相应地拉伸高度并进行线性插值。该数字实际上是为了校正弧长。1
sin(1)
1.1884
sin(1)^-1
当然,你也可以做一些数学运算。
正确的方法
为了获得“正确”的线路而不用像上面那样的肮脏伎俩,您可以使用以下命令:
\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}
此图生成1
具有曲率的精确长度的线\k
。我在这里使用了参数图,而不是arc
tikz 内置的图。
注解
为了制作这些动画,我使用了ImageMagick
:
convert -delay 10 -loop 0 -background white -alpha remove the.pdf result.gif
可以使用以下方法创建更平滑的版本:
\foreach \k in {0,0.04,...,1.001}{
而不是另一\foreach
行。要微调相应的动画(并使其稍微大一些):
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
在这里,我手动选择了不同页面范围的延迟(以百分之一秒为单位),从零开始0
,通过在 pdf 文件名后添加\[page\]
。第一张图片和最后一张图片应显示 1 秒,其间所有内容显示 4/100 秒。
笔记:根据您的 shell,您可能不需要转义方括号,即使用the.pdf[..]
而不是the.pdf\[..\]
。感谢@AndréC 的提及。
笔记:虽然-background white -alpha remove
图片中没有白色矩形作为背景应该可以正常工作,但它似乎并不总是能正常工作。所以我再次在代码中添加了矩形。
答案2
只是为了好玩,一个允许完成初始动画的代码,当然基于显示的优秀代码,以同样的方式我使用 Imagemagick 生成 gif 中的输出;原始文件有 113 帧 @ 105Kb,代码生成 110 帧 @ 648Kb,这可能会因 imagemagic 设置而异;但是,原始文件有一些具有特定延迟的帧,并且使用 imagemagick 声明它们的方式非常繁琐,特别是对于我使用 arara 进行编译的人来说,所以我使用了另一个程序(fireworks),它允许我在图形界面中编辑延迟,导出的文件自动压缩为 176Kb。
% 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}
答案3
根据 nox 的良好回答,这是一个仅绘制圆段而不是椭圆的版本:它用于确定以不同角度开始的pgfmath
弧长圆段的半径。1
(1,0)
\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}