I want to create an animation of satellites. I am using the code below. However I'd like it to run smoothly so I want to produce many frames. It turns out the maximum number of frames I can create via \foreach is 45. If I change to 46 I get the error Dimension too large.

So, how can I do 45+ \foreach loops?

\setbeamertemplate{navigation symbols}{}


  \pgfmathsetmacro{\Jradius}{0.3}   % Jupiter radius
  \pgfmathsetmacro{\IoOrbit}{1}   % Io radius
  \pgfmathsetmacro{\Iradius}{0.1} % Earth radius

  \fill[red] (0,0) circle (\Jradius);

  \draw[thin] (0,0) circle (\IoOrbit);

  \pgfmathsetmacro{\N}{45} %If 46 or more, then error.
  \foreach \k in {0,1,...,\N}{
        \fill[gray] ({cos(\theta)},{sin(\theta)}) circle (\Iradius);
  • It is not the \foreach it is the ` \pgfmathsetmacro{\theta}{360*\k/\N}` that causes the problem. No idea why – daleif Sep 29 '15 at 12:49
  • Of course: 360*46 is too large for it to handle, but (360/N)*\k is not – daleif Sep 29 '15 at 12:51
  • 1
    Reverse the order {360/\N*\k} – percusse Sep 29 '15 at 12:51
  • Didn't imagine the order would be important, I guess it does because 360*46 is bigger than the allowed number latex handles? – PepeToro Sep 29 '15 at 12:54

In the calculation of \pgfmathsetmacro{\theta}{360*\k/\N} 360*\k easily becomes bigger than what LaTeX can handle. Reversing the multiplication order, solves this:

| improve this answer | |

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.