1

My error is with the "Dimension too large" when I compile the next code, Im trying to make an animation with function sin and cos. The error is in line

\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}
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. I'm afraid you've encountered a famous and difficult to solve bug in PGF... – yo' Mar 11 '15 at 14:45
1

Then let's use the expl3 floating point unit instead, in particular its fp_eval:n{...} function.

Also, the \multiframe command should be used to build the loop around the parameterized tikzpicture, which is to be preferred over the \whiledo solution.

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

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.