0

I was blocked on this point, I'm going to compile a code in which I'm using the command foreach:

\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
....
}

when i compile this code i get the following error:

 Runaway argument? {\pgfkeysvalueof {/pgf/inner ! TeX capacity
 exceeded, sorry [main memory size=5000000]. <argument> ...pgf@xc
 {\pgfkeysvalueof {/pgf/inner 
                                                   xsep}}\advance \pgf@x by 2... l.98 }
        !  ==> Fatal error occurred, no output PDF file produced!
 Transcript written on fig_serie_2.log.

her is my code:

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{animate}
\usepackage{ifthen}
\usetikzlibrary{patterns}% 
\def\relRad{0.3}
\def\RodLength{1.65}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{animateinline}[loop, poster = first, controls=false]{24}
%\foreach \iBngle in {0,2,...,100}{
\multiframe{100}{iBngle=0+2}{
\pgfmathsetmacro{\iAngle}{140}%35
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\useasboundingbox[tdplot_screen_coords] (-2.05,-1.2) rectangle 
(2.5,1.5);
\coordinate (O) at (0,0,0);
\node[red, left] at (O) {$O$};
\draw[thick,->] (O) -- (2,0,0) node[anchor=north]{$x_0$};
\draw[thick,->] (O) -- (0,1.5,0) node[anchor=west]{$y_0$};
\draw[thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z_0$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, left]{$\vec i_0$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, below]{$\vec j_0$};
\draw[thick,->] (O) -- (0,0,0.3) node[anchor=south, right]{$\vec 
k_0$};
\draw[thick, opacity=0.3] (-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\fill[red,opacity=0.2](-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\tdplotdrawarc[thick, color=red]{(2,-1.5,0)}{-0.3}{-90}{0}{anchor=180}
{$\pi/2$}% <-
\tdplotdrawarc[thick, color=red, ->]{(O)}{0.5}{0}{\iAngle+\iBngle}
{anchor=180, below}{$\omega\cdot t$}%
\tdplotdrawarc[thick,dotted, color=violet, ->]{(O)}{0.55}{90}
{90+\iAngle+\iBngle}{anchor=180,above}{$\omega\cdot t$}
\tdplotdrawarc[thick, color=purple, dashed]{(O)}
{\RodLength*\iBngle/180}{0}{360}{anchor=180}{} %%changed
\tdplotsetrotatedcoords{\iAngle+\iBngle}{00}{0}%%changed
\begin{scope}[tdplot_rotated_coords]
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (2.5,0,0)node[above]
{$x_1$};
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (0,2.5,0)node[above] 
{$y_1$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, above left]{$\vec 
i_1$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, above]{$\vec j_1$};
\end{scope}
\ifthenelse{\iBngle<180}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}
\end{tikzpicture}
}
\end{animateinline}
\end{document}
moradov
  • 427
  • 1
    please edit your example so people can run it and reproduce the error to debug, it is very hard to debug fragments that use undefined commands. – David Carlisle Mar 15 '18 at 23:02
  • 1
    I can't compile your code either but I guess the problem is \foreach \jar in {\iar, \tar, ...,\tar}{. Try replacing it by \foreach \jar in {\iar, \tar}{ or something else that makes sense. –  Mar 16 '18 at 00:03

1 Answers1

3

The real problem is, as you stated, in the \foreach \jar in {\iar, \tar, ...,\tar} line. The values of \iar and \tar when TeX arrives here are both zero, so the command reads \foreach \jar in {0, 0, ...,0}, which results in an infinite loop :)

The value of the loop increment (\tar) cannot be zero, otherwise this will occur. The value of both \iar and \tar are zero because \iBngle is zero.

So the first fix is to change the line

\multiframe{100}{iBngle=0+2}{

to something else, other than zero. Since the increment here is two, I suggest an odd value, so that it'll never be zero, no matter how many iterations.

The second issue, is these lines:

\pgfmathtruncatemacro{\iar}{{\RodLength*\iBngle/180}}
\pgfmathtruncatemacro{\tar}{{(\RodLength*\iBngle/360)-\iar}}

The \pgfmathtruncatemacro does exactly as it says. You have \RodLength = 1.65 and, after the first fix, \iBngle = 1. This gives 1.65*1/180 = 0.009 that, after truncation is zero. And again both \iar and \tar are zero.

Replace these lines by:

\pgfmathparse{\RodLength*\iBngle/180}
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult

and you'll have the proper value, without truncation.

I fixed your code and it runs fine, but unfortunately my PDF viewer doesn't play the animation, so I couldn't check if it works.

On a side note, this line: \foreach \jar in {\iar, \tar, ...,\tar}. Is it supposed to be like this? As far as I understand loops, this will iterate only once for \jar=\iar, and if this is correct, then there's no point in using the \foreach at all.

Here's the full code:

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{animate}
\usepackage{ifthen}
\usetikzlibrary{patterns}% 
\def\relRad{0.3}
\def\RodLength{1.65}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{animateinline}[loop, poster = first, controls=false]{24}
%\foreach \iBngle in {0,2,...,100}{
\multiframe{100}{iBngle=1+2}{
\pgfmathsetmacro{\iAngle}{140}%35
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\useasboundingbox[tdplot_screen_coords] (-2.05,-1.2) rectangle 
(2.5,1.5);
\coordinate (O) at (0,0,0);
\node[red, left] at (O) {$O$};
\draw[thick,->] (O) -- (2,0,0) node[anchor=north]{$x_0$};
\draw[thick,->] (O) -- (0,1.5,0) node[anchor=west]{$y_0$};
\draw[thick,->] (O) -- (0,0,1.5) node[anchor=south]{$z_0$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, left]{$\vec i_0$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, below]{$\vec j_0$};
\draw[thick,->] (O) -- (0,0,0.3) node[anchor=south, right]{$\vec 
k_0$};
\draw[thick, opacity=0.3] (-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\fill[red,opacity=0.2](-2,-1.5,0) -- (2,-1.5,0) -- (2,1.5,0) --(-2,1.5,0) -- cycle;
\tdplotdrawarc[thick, color=red]{(2,-1.5,0)}{-0.3}{-90}{0}{anchor=180}
{$\pi/2$}% <-
\tdplotdrawarc[thick, color=red, ->]{(O)}{0.5}{0}{\iAngle+\iBngle}
{anchor=180, below}{$\omega\cdot t$}%
\tdplotdrawarc[thick,dotted, color=violet, ->]{(O)}{0.55}{90}
{90+\iAngle+\iBngle}{anchor=180,above}{$\omega\cdot t$}
\tdplotdrawarc[thick, color=purple, dashed]{(O)}
{\RodLength*\iBngle/180}{0}{360}{anchor=180}{} %%changed
\tdplotsetrotatedcoords{\iAngle+\iBngle}{00}{0}%%changed
\begin{scope}[tdplot_rotated_coords]
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (2.5,0,0)node[above]
{$x_1$};
\draw[thick, dashed, opacity=1, ->] (0,0,0) -- (0,2.5,0)node[above] 
{$y_1$};
\draw[thick,->] (O) -- (0.3,0,0) node[anchor=north, above left]{$\vec 
i_1$};
\draw[thick,->] (O) -- (0,0.3,0) node[near end, above]{$\vec j_1$};
\end{scope}
\ifthenelse{\iBngle<180}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathparse{\RodLength*\iBngle/180}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}{
\tdplotsetrotatedcoords{{\iAngle+\iBngle}}{00}{0} %<- changed that in order to rotate the rod
\begin{scope}[tdplot_rotated_coords]
\pgfmathparse{\RodLength*\iBngle/180}%L=\iBngle*x=\RodLength*\iBngle/360%360 ou 180 angles finale % le pas
\let\iar\pgfmathresult
\pgfmathparse{(\RodLength*\iBngle/360)-\iar}
\let\tar\pgfmathresult
\foreach \jar in {\iar, \tar, ...,\tar}{
\draw[ultra thick, color=orange, opacity=1] (0,0,0) -- 
(\RodLength,0,0)node[near end, below left] {$(T)$};
\coordinate[label=below right:$C$] (A1) at 
({\RodLength*\iBngle/180},0,0.3); 
\fill[blue,thick] (A1) circle (0.3pt);
\coordinate[label=above:$I_1$] (I1) at 
({\RodLength*\iBngle/180},0,0);%changed
\fill[blue,thick] (I1) circle (0.3pt);}
\end{scope}
\tdplotsetrotatedcoords{{\iAngle+130}}{90}{0} %<-
\begin{scope}[tdplot_rotated_coords]
\draw[pattern=north west lines, pattern color=blue, opacity=0.5 ] (A1) 
 circle (\relRad);
\node[] at (45:0.4cm){$D$};
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$k_1$};  %<-
\draw[-latex,blue] (A1) -- ++(0,0,0.7)node[below]{$i_1$};  %<-
\draw[-latex,blue] (A1) -- ++({-0.7*cos(\iBngle/\relRad+\iAngle)},0,{0.7*sin(\iBngle/\relRad+\iAngle)})node[right]{$i_2$}; %<-
\draw[-latex,blue] (A1) -- ++({-0.7*sin(\iBngle/\relRad)},0,{-0.7*cos(\iBngle/\relRad)})node[below]{$k_2$};  %<-
\end{scope}}
\end{tikzpicture}
}
\end{animateinline}
\end{document}
  • thank you @Phelype Oleinik, can you label for me a link to a document, in order to understand the difference between \pgfmathtruncatemacro and \pgfmathparse – moradov Mar 16 '18 at 00:38
  • 1
    @moradov There's not much secret to it. \pgftruncatemacro will perform the calculation and truncate the result and store the result in the given macro. \pgfmathparse will also perform the calculation, but without truncation, and the result will be stored in \pgfmathresult (that's why after \pgfmathparse I used \let\iar\pgfmathresult). You can find more detailed information about this macros in chapter 54 -- Floating Point Unit Library of the PGF manual. – Phelype Oleinik Mar 16 '18 at 00:47
  • 1
    @moradov You're welcome :) – Phelype Oleinik Mar 16 '18 at 01:16