2

Is there any possibility to take coordinates in an animated Tikz from a vector? For example in the code below which I found at (http://www.texample.net/tikz/examples/sine-and-cosine-functions-animation/) instead of increasing the angle via \stepcounter to take the angle from an vector with the value angle=[10,12,15,...] for example. I want to draw an animated quarter car an take the displacement of the masses from vectors I calculated with Matlab. Thank you!

    % 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
    BTW, don't use \whiledo but \multiframe for loops with parameters around animate frames. – AlexG Aug 24 '15 at 12:15
3

The LaTeX3 "clist" data type can be used as an Array-like container of arbitrary data. A clist variable is initialised from a comma separated list. Individual elements are accessed by index:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.