我的错误是,当我编译下一个代码时,出现“尺寸太大”的错误,我试图用函数 sin 和 cos 制作动画。错误位于行
\draw[line width=1.pt,smooth,samples=50,domain=0.001:\theangle,blue] plot(\x+3.14,{sin(((\x))*180/pi)});
\documentclass[spanish,10pt]{beamer}
\usepackage{color}
\usepackage{tikz}
\usepackage{hyperref}
\hypersetup{pdfpagemode=FullScreen}
\usepackage{ifthen}
\usepackage{animate}
\usecolortheme{whale}
\newcounter{angle}
\setcounter{angle}{0}
%
\begin{document}
%
%
%
\begin{frame}[fragile]{Sine and Cosine functions}
\begin{center}
\begin{animateinline}[loop, poster = first]{30}
%
\whiledo{\theangle<359}{
%
\begin{tikzpicture}
% Axis
\draw[thick,->] (-1.5,0)--(1.5,0) node[below] {$x$}; % x axis
\draw[thick,->] (0,-1.5)--(0,1.5) node[left] {$y$}; % y axis
\draw[cyan,thick] (0,0) circle (1cm);
\node[red,below] at (1.2,0) {1};
\node[red,above] at (0.4,-1.5) {-1};
%
%Axis auxiliar
\draw[thick,->] (3.14,0)--(10,0) node[below] {$x$}; % x axis
\draw[thick,->] (3.14,-1.5)--(3.14,1.5) node[left] {$y$}; % y axis
%
\draw[ultra thick,red] (0,0) -- (0,0 |- \theangle:1cm); % UpOn x axis
\draw[ultra thick,blue] (0,0) -- (\theangle:1cm |- 0,0); % UpOn y axis
%
\draw[densely dotted,blue] (\theangle:1cm) -- (\theangle:1cm |- 0,0); % vertical line
\draw[densely dotted,red] (\theangle:1cm) -- (0,0 |- \theangle:1cm); % horizontal line
%
\draw[ultra thick,->,rotate=\theangle] (0,0) -- (1,0);
% grid
\draw [dash pattern=on 1pt off 1pt, xstep=1.57cm,ystep=1.0cm] (3.14,-1.5) grid (9.29,1.5);
% funciones sen y cos
\draw[line width=1.pt,smooth,samples=50,domain=0.001:\theangle,blue] plot(\x+3.14,{sin(((\x))*180/pi)});
\draw[line width=1.pt,smooth,samples=100,domain=0.0:\theangle,red] plot(\x+3.14,{cos(((\x))*180/pi)});
\node[red,blue,right] at (-2,-3.8)
{\footnotesize$\cos(\,\theangle^{\mathrm{o}}\,) = \pgfmathcos{\theangle}\pgfmathresult$};
\node[red,red,right] at (-2,-3.4)
{\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
那么我们就用expl3
浮点单元来代替吧,特别是它的fp_eval:n{...}
功能。
此外,\multiframe
应该使用命令来构建围绕参数化的循环tikzpicture
,这比\whiledo
解决方案更可取。
\documentclass[spanish,10pt]{beamer}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{expl3}
\usepackage{hyperref}
%\hypersetup{pdfpagemode=FullScreen}
\usepackage{animate}
\ExplSyntaxOn
\let\fpeval\fp_eval:n
\ExplSyntaxOff
\usecolortheme{whale}
\begin{document}
%
\begin{frame}[fragile]{Sine and Cosine functions}
\begin{center}
\begin{animateinline}[loop]{30}
\multiframe{361}{iAngle=0+1}{
\begin{tikzpicture}
% Axis
\draw[thick,->] (-1.5,0)--(1.5,0) node[below]{$x$}; % x axis
\draw[thick,->] (0,-1.5)--(0,1.5) node[left] {$y$}; % y axis
\draw (0,0) circle (1cm);
\node[red,below] at (1.2,0) {1};
\node[red,above] at (0.4,-1.5) {-1};
%
%Axis auxiliar
\draw[thick,->] (2.0,0)--(9,0) node[below] {$x$}; % x axis
\draw[thick,->] (2.0,-1.5)--(2.0,1.5) node[left] {$y$}; % y axis
%
\draw[ultra thick,red] (0,0) -- (0,0 |- \iAngle:1cm); % UpOn x axis
\draw[ultra thick,blue] (0,0) -- (\iAngle:1cm |- 0,0); % UpOn y axis
%
\draw[densely dotted,blue] (\iAngle:1cm) -- (\iAngle:1cm |- 0,0); % vertical line
\draw[densely dotted,red] (\iAngle:1cm) -- (0,0 |- \iAngle:1cm); % horizontal line
%
\draw[ultra thick,->,rotate=\iAngle] (0,0) -- (1,0);
%
% grid
\foreach \i in {1, 2, 3 ,4} \draw [dash pattern=on 1pt off 1pt] ($(\i*pi/2+2.0,-1.5)$)--($(\i*pi/2+2.0,1.5)$);
\foreach \i in {-1, 1} \draw [dash pattern=on 1pt off 1pt] (2,\i)--(8.8,\i);
%
%the arc
\draw [cyan, ultra thick] (1cm,0) arc [start angle=0, end angle=\iAngle, radius=1cm];
\draw[line width=1.pt, cyan] (2,0)--(\fpeval{2+\iAngle*pi/180},0);
%
% funciones sen y cos
\draw[line width=1.pt,smooth,samples=50,domain=2.0:\fpeval{2+\iAngle*pi/180},red] plot (\x,\fpeval{sin(\x-2)});
\draw[line width=1.pt,smooth,samples=50,domain=2.0:\fpeval{2+\iAngle*pi/180},blue] plot (\x,\fpeval{cos(\x-2)});
\node[red,blue,right] at (-2,-3.8)
{\footnotesize$\cos(\,\iAngle^{\mathrm{o}}\,) = \fpeval{round(cosd(\iAngle),4)}$};
\node[red,red,right] at (-2,-3.4)
{\footnotesize$\cos(\,\iAngle^{\mathrm{o}}\,) = \fpeval{round(sind(\iAngle),4)}$};
\end{tikzpicture}
}
\end{animateinline}
\end{center}
\end{frame}
%
\end{document}