文章目录
引言
我们知道,一般我们作图都是用stata、matlab或其他软件,然后再将作出的图片另做他用,如做定格动画。但一般很少人直接用latex去做,原因有两点:(1)作出的图为PDF版本,还需通过一定的途径转化为其他格式如PNG格式;(2)目前很多软件如imagemagick、Adobe acrobat DC转出的图片效果不是很好(失真率很大);(3)定格动画本身需要很多图片素材,一般需要跑循环才能完成,而latex的循环语句比较难阅读和使用的。本文的目的在于为大家创建一个用latex做定格动画的模式,以供大家套用。
先做出单张PDF图
这里我们先做一个角度为 12 0 ∘ 120^\circ 120∘的图。
代码如下:
%采用pdflatex编译(速度大大提升)
\documentclass[12pt,a4paper,UTF8]{ctexart}
\usepackage{tikz}
\usepackage{siunitx} %需要用到\ang[options]{degrees}命令
\newcommand{\iangle}{120}
%\usepackage{ctex}
\usepackage[landscape]{geometry} %使得页面横置
%对于中文字体的处理:pdfLaTeX用CJK包或ctex包会出错,而用\documentclass[UTF8]{ctexart}则没有问题;XeLaTeX用CJK包,则可以正确编译。
\begin{document}
\begin{tikzpicture}[scale=1.5] %scale参数可以使得图形放大一定的倍数而本身的字体大小可以保持不变。
%画左边的圆
%scope环境里够成一整个区块,然后可以使这一整个区块进行平移。
\begin{scope}[xshift=-1.75cm]
\fill[fill=gray,fill opacity=0.2]
(0,0) -- (0:1) arc (0:\iangle:1) -- cycle;
\filldraw[fill=gray,fill opacity=0.5]
(0,0) --(0:0.3) arc (0:\iangle:0.3) -- cycle;
\draw[->] (-1.2,0) -- (1.2,0);
\draw[->] (0,-1.2) -- (0,1.2);
\draw[thick] (0,0) circle (1);
\coordinate[label=\iangle:$P$] (P) at (\iangle:1);
\coordinate[label=below:$P_0$] (P0) at (P |- 0,0);
\draw (0,0) -- (P);
\draw (P) -- (P0);
\node[right] at (\iangle/2:0.3) {\ang{\iangle}};
\end{scope}
%画右边的正弦曲线
\draw[->] (0,0) -- ({rad(210)},0);
\draw[->] (0,-1.2) -- (0,1.2);
\draw[thick,domain=0:rad(210)] plot(\x,{sin(\x r)}) node[right] {$\sin x$};
\foreach \t in {0,90,180} {
\draw ({rad(\t)},-0.05) -- ({rad(\t)},0.05);
\node[below,outer sep=2pt,fill=white,font=\small]
at ({rad(\t)},0) {\ang{\t}};
}
\foreach \y in {-1,1} {
\draw (-0.05,\y) -- (0.05,\y);
}
\coordinate[label=above:$Q$] (Q) at ({rad(\iangle)},{sin(\iangle)});
\coordinate[label=below:$Q_0$] (Q0) at (Q |- 0,0);
\draw (Q) -- (Q0);
%左右相互连接
\draw[dashed] (P) -- (Q);
\end{tikzpicture}
\end{document}