![Tikz 动画图形坐标来自矢量](https://linux22.com/image/317651/Tikz%20%E5%8A%A8%E7%94%BB%E5%9B%BE%E5%BD%A2%E5%9D%90%E6%A0%87%E6%9D%A5%E8%87%AA%E7%9F%A2%E9%87%8F.png)
是否有可能从矢量中获取动画 Tikz 中的坐标?例如,在下面的代码中,我在 (http://www.texample.net/tikz/examples/sine-and-cosine-functions-animation/),而不是通过 \stepcounter 增加角度,例如从值为 angle=[10,12,15,...] 的向量中获取角度。我想绘制一个动画的四分之一汽车,并从我用 Matlab 计算的向量中获取质量位移。谢谢!
% Sine and Cosine functions animation
%
% Author:
% Efraín Soto Apolinar.
% http://www.aprendematematicas.org/
%
% This animation helps explain the
% geometric interpretation of the
% sine and cosine functions.
%
\documentclass[spanish,10pt]{beamer}
\usepackage[ansinew]{inputenc} % Language = Spanish
%
\usepackage{color}
\usepackage{tikz}
\usepackage{hyperref}
\hypersetup{pdfpagemode=FullScreen}
\usepackage{ifthen}
\usepackage{animate}
%
\usetheme{Warsaw}
\usecolortheme{whale}
%
%
%
\newcounter{angle}
\setcounter{angle}{0}
%
\begin{document}
%
%
%
\begin{frame}[fragile]{Sine and Cosine functions}
\begin{center}
\begin{animateinline}[loop, poster = first, controls]{30}
%
\whiledo{\theangle<359}{
%
\begin{tikzpicture}
% Axis
\draw[thick,->,blue] (-3,0)--(3,0) node[below] {$x$}; % x axis
\draw[thick,->,blue] (0,-3)--(0,3) node[left] {$y$}; % y axis
\draw[red,thick] (0,0) circle (2.5cm);
\node[red,below] at (2.6,0) {1};
\node[red,above] at (0.1,-2.5) {1};
%
\draw[ultra thick,cyan] (0,0) -- (0,0 |- \theangle:2.5cm); % UpOn x axis
\draw[ultra thick,orange] (0,0) -- (\theangle:2.5cm |- 0,0); % UpOn y axis
%
\draw[densely dotted,orange] (\theangle:2.5cm) -- (\theangle:2.5cm |- 0,0); % vertical line
\draw[densely dotted,cyan] (\theangle:2.5cm) -- (0,0 |- \theangle:2.5cm); % horizontal line
\draw[ultra thick,red,->,rotate=\theangle] (0,0) -- (2.5,0);
\node[red,orange,right] at (0,-3.5)
{\footnotesize$\cos(\theangle^{\mathrm{o}}) = \pgfmathcos{\theangle}\pgfmathresult$};
\node[red,cyan,right] at (0,-3.1)
{\footnotesize$\sin(\theangle^{\mathrm{o}}) = \pgfmathsin{\theangle}\pgfmathresult$};
\end{tikzpicture}
%
\stepcounter{angle}
\ifthenelse{\theangle<359}{
\newframe
}{
\end{animateinline}
}
}
\end{center}
\end{frame}
%
%
\end{document}
答案1
LaTeX3“clist”数据类型可用作任意数据的类似数组的容器。clist 变量由逗号分隔的列表初始化。各个元素可通过索引访问:
\documentclass[spanish,10pt]{beamer}
\usepackage[ansinew]{inputenc} % Language = Spanish
%
\usepackage{color}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{ifthen}
\usepackage{animate}
%
\usetheme{Warsaw}
\usecolortheme{whale}
%
\usepackage{expl3}
%create aliases from clist related functions
\ExplSyntaxOn
\let\clistSet\clist_set:Nn %create clist var from comma separated objects
\let\clistCount\clist_count:N %get number of items in clist
\let\clistItem\clist_item:Nn %get clist item by index (1 <= \clistCount<clist var>)
\ExplSyntaxOff
%
\begin{document}
%
\begin{frame}[fragile]{Sine and Cosine functions}
\begin{center}
\clistSet\myClist{0,10,30,45,50,90,179}
\begin{animateinline}[loop, poster = first, controls]{30}
\multiframe{\clistCount\myClist}{i=1+1}{ % "i" later be used as index
\begin{tikzpicture}
% axes
\draw[thick,->,blue] (-3,0)--(3,0) node[below] {$x$}; % x axis
\draw[thick,->,blue] (0,-3)--(0,3) node[left] {$y$}; % y axis
\draw[red,thick] (0,0) circle (2.5cm);
\node[red,below] at (2.6,0) {1};
\node[red,above] at (0.1,-2.5) {1};
%
\draw[ultra thick,cyan] (0,0) -- (0,0 |- \clistItem\myClist{\i}:2.5cm); % UpOn x axis
\draw[ultra thick,orange] (0,0) -- (\clistItem\myClist{\i}:2.5cm |- 0,0); % UpOn y axis
%
\draw[densely dotted,orange] (\clistItem\myClist{\i}:2.5cm) -- (\clistItem\myClist{\i}:2.5cm |- 0,0); % vertical line
\draw[densely dotted,cyan] (\clistItem\myClist{\i}:2.5cm) -- (0,0 |- \clistItem\myClist{\i}:2.5cm); % horizontal line
\draw[ultra thick,red,->,rotate=\clistItem\myClist{\i}] (0,0) -- (2.5,0);
\node[red,orange,right] at (0,-3.5)
{\footnotesize$\cos(\clistItem\myClist{\i}^{\mathrm{o}}) = \pgfmathcos{\clistItem\myClist{\i}}\pgfmathresult$};
\node[red,cyan,right] at (0,-3.1)
{\footnotesize$\sin(\clistItem\myClist{\i}^{\mathrm{o}}) = \pgfmathsin{\clistItem\myClist{\i}}\pgfmathresult$};
\end{tikzpicture}
}
\end{animateinline}
\end{center}
\end{frame}
%
\end{document}