
Estou tentando modificar a animação apresentada aquiExemplo: animação das funções Seno e Cossenoincluir phase
, então a rotação começará cada vez em um ângulo diferente, ou seja, phase =[0, 45 ,-45]
então usei foreach como abaixo, a animação original é mostrada emExemplo: animação das funções Seno e Cosseno, mas o código não funcionou(descomente os comandos relacionados à animação para verificar o erro que estou recebendo).
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
%\newcounter{theangle}
%\setcounter{theangle}{0}
\begin{tikzpicture}
\def\angle{45};
\fill[fill=red] (0,0) -- plot [domain=0:pi/180*\angle] (\x,{sin(\x r)}) -- (pi/180*\angle,0) -- cycle;
\end{tikzpicture}
%\begin{animateinline}[loop, poster = first,controls]{40}
%
%\foreach \angle in {0,45,-45}
%\whiledo{\angle<359}{
\foreach \angle in {0,10,...,360}
{
\begin{tikzpicture}
%\fill[blue!50] (-1,0) arc (0:\angle:1) -- (-2,0) -- cycle;
%\fill[blue!50] plot[smooth,domain=0:\angle] (pi/180*\x,{sin(\x)}) |- (0,0);
\def\radangle{pi/180*\angle};
\fill[blue!50] (-1,0) arc (0:\angle:1) -- (-2,0) -- cycle;
%\fill[fill=red] (0,0) -- plot [domain=0:\radangle] (\x,{sin(\x r)}) -- (\radangle,0) -- cycle;
\draw (-2,0) +(\angle:1) circle (2pt) -- (pi/180*\angle,{sin(\angle)}) circle (2pt);
\draw (-3.5,0) -- (7,0);
\foreach \deg in {90, 180, 270, 360}
\draw (pi/180*\deg,2pt) -- (pi/180*\deg,-2pt) node[below] {$\deg^\circ$};
\draw (0,-1.2) -- (0,1.2);
\foreach \y in {-1,-0.5,0.5,1}
\draw (2pt,\y) -- (-2pt,\y) node[left] {$\y$};
\draw plot[smooth,domain=0:360] (pi/180*\x,{sin(\x)});
\draw (-2,0) circle (1);
\end{tikzpicture}
%
% \stepcounter{theangle}
% \ifthenelse{\theangle<359}{\newframe}{
% \end{animateinline}}
}
\end{document}
Responder1
O exemplo usa \clist_map_inline:nn
from LaTeX3 em vez de TikZ \foreach
para iterar na lista de mudanças de fase separadas por vírgula. Por algum motivo, \foreach
não funciona por dentro animateinline
.
Algumas pausas ( \newframe*
) são colocadas em pontos de animação adequados; clique no botão play ou no widget de animação para continuar:
(Um navegador baseado em Chromium é recomendado para visualizar a versão SVG, pois o Firefox é um pouco lento.)
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz,animate}
\ExplSyntaxOn
\let\clistMap\clist_map_inline:nn
\ExplSyntaxOff
\newcommand{\drawit}[2]{% #1 angle (0<=#1<=360)
\begin{tikzpicture} % #2 phase shift
\pgfmathsetmacro\angleRad{pi/180*(#1+#2)}
\pgfmathsetmacro\angleDeg{#1+#2}
\pgfmathsetmacro\unshiftedRad{pi/180*(#1)}
\fill[blue!50] (-2,0) -- ++(#2:1) arc (#2:\angleDeg:1) -- cycle;
\draw (-2,0) +(\angleDeg:1) circle (2pt) -- (\unshiftedRad,{sin(\angleDeg)}) circle (2pt);
\draw (-3.5,0) -- (7,0);
\foreach \deg in {90, 180, 270, 360}
\draw (pi/180*\deg,2pt) -- (pi/180*\deg,-2pt) node[below] {$\deg^\circ$};
\draw (0,-1.2) -- (0,1.2);
\foreach \y in {-1,-0.5,0.5,1}
\draw (2pt,\y) -- (-2pt,\y) node[left] {$\y$};
\draw plot[smooth,domain=0:360] (pi/180*\x,{sin(\x+#2)});
\draw (-2,0) circle (1);
\node [anchor=north east] at (current bounding box.north east) {$\varphi=#2^\circ$};
\end{tikzpicture}%
}
\begin{document}
\begin{animateinline}[controls]{30}
\clistMap{0,45,-45}{%
\drawit{0}{#1}
\newframe*
\multiframe{360}{i=1+1}{\drawit{\i}{#1}}%
\ifthenelse{#1=-45}{}{\newframe*}%
}
\end{animateinline}
\end{document}