1

I am facing a compilation error in a weird way. I have trimmed my code to the maximum but still my MWE is not too small, so I'll focus first on the weird part :

    \foreach \j in {0,1,...,5}{
        \pgfmathsetmacro{\AngleEntree}{-10*\j}

        \coordinate (centreCardan) at (-20,{-18*\j},5);

        % Circle 
        \begin{scope}[tdplot_screen_coords]
        \draw[red,ultra thick,dashed] (centreCardan) circle (\r);
        \end{scope}

        %Tube
        \coordinate (centrePivVR) at ($(centreCardan)+ ({-5*cos(\AngleEntree)},{-5*sin(\AngleEntree)},0)$);
        %%
        \Pivot{(centrePivVR)}{blue, ultra thick}{ }{cos(\AngleEntree)}{sin(\AngleEntree)}{0}

    }

You can see the loop where it happens, (centreCardan) is a point used to place a figure, and I define it in each loop to offset every new figure under the previous one.

You can see the iterator is \j, and I multiply if by 18 to get the Y coordinate for (centreCardan) . If I stop \j at 4, it compiles, but with 5 it doesn't.

Up to this point nothing too surprising, but it gets weird if you use 10 instead of 18 as a multiplicator, then you can go up to 21 with \j ( 21 * 10 =210 > 5*18 = 90 ) so I don't quite understand what's happening.

If I remove the \Pivot line \j can go up to 38 with a 18 multiplicator

If you are able to dive in a 130 lines code, here is my MWE :

\documentclass[tikz,border=5pt]{standalone}
\usepackage{tikz,esvect,tikz-3dplot} 

% Créer des canvas personnalisés pour toutes les orientations
\makeatletter
\tikzoption{canvas is plane}[]{\@setOxy#1}
\def\@setOxy O(#1,#2,#3)x(#4,#5,#6)y(#7,#8,#9)%
  {\def\tikz@plane@origin{\pgfpointxyz{#1}{#2}{#3}}%
   \def\tikz@plane@x{\pgfpointxyz{#4}{#5}{#6}}%
   \def\tikz@plane@y{\pgfpointxyz{#7}{#8}{#9}}%
   \tikz@canvas@is@plane
  }
\makeatother  

%%%%% Environnement scope dans un canvas personnalisé avec normalisation du vecteur directeur
\newenvironment{NouveauPlan}[3]
{
    \pgfmathsetmacro{\DoublCondi}{0}
    \ifdim\VaxecY pt=0 pt
        \pgfmathsetmacro{\DoublCondi}{\DoublCondi+1}
    \fi
    \ifdim\VaxecZ pt=0 pt
        \pgfmathsetmacro{\DoublCondi}{\DoublCondi+1}
    \fi
    \ifdim\DoublCondi pt=2 pt
        \pgfmathsetmacro{\XcordY}{1}
        \pgfmathsetmacro{\XcordZ}{0}
        \pgfmathsetmacro{\YcordX}{0}
        \pgfmathsetmacro{\YcordY}{0}
        \pgfmathsetmacro{\YcordZ}{1}
    \else
        \pgfmathsetmacro{\NormX}{sqrt((#3)*(#3)+(#2)*(#2))}
        \pgfmathsetmacro{\NormY}{sqrt( ((#2)*(#2)+(#3)*(#3))*((#2)*(#2)+(#3)*(#3)) +  (#1)*(#2)*(#1)*(#2)  +  (#1)*(#3)*(#1)*(#3)  )}
        \pgfmathsetmacro{\XcordY}{#3/\NormX}
        \pgfmathsetmacro{\XcordZ}{(-1)*(#2)/\NormX}
        \pgfmathsetmacro{\YcordX}{(-1)*((#2)*(#2)+(#3)*(#3))/\NormY}
        \pgfmathsetmacro{\YcordY}{(#1)*(#2)/\NormY}
        \pgfmathsetmacro{\YcordZ}{(#1)*(#3)/\NormY}
    \fi
%%%%%%%
\begin{scope}[canvas is plane={O(0,0,0)x(0,\XcordY,\XcordZ)y(\YcordX,\YcordY,\YcordZ)}]
}{\end{scope}}


%% Fonctions de Calcul %%

\newcommand*{\NormerVect}[3]{
\pgfmathsetmacro{\NormV}{sqrt((#1)*(#1)+(#2)*(#2)+(#3)*(#3))}
\pgfmathsetmacro{\VncX}{#1/\NormV}
\pgfmathsetmacro{\VncY}{#2/\NormV}
\pgfmathsetmacro{\VncZ}{#3/\NormV}
}

\newcommand*{\MultipliVect}[4]{
\pgfmathsetmacro{\VmcX}{#1*(#4)}
\pgfmathsetmacro{\VmcY}{#2*(#4)}
\pgfmathsetmacro{\VmcZ}{#3*(#4)}
}

\newcommand*{\CalculAxe}[3]{
\pgfmathsetmacro{\NormV}{sqrt((#1)*(#1)+(#2)*(#2)+(#3)*(#3))}
\pgfmathsetmacro{\VaxecX}{#1/\NormV}
\pgfmathsetmacro{\VaxecY}{#2/\NormV}
\pgfmathsetmacro{\VaxecZ}{#3/\NormV}
% Vecteur unitaire de l'axe
\coordinate (AxeUni) at (\VaxecX,\VaxecY,\VaxecZ);
\MultipliVect{\VaxecX}{\VaxecY}{\VaxecZ}{\l/2}
\coordinate (AxeMoitie) at(\VmcX,\VmcY,\VmcZ);

}

%% Liaisons Pivot %%

\newcommand*{\Pivot}[6]{
\CalculAxe{#4}{#5}{#6}

\coordinate (centre) at #1;
\coordinate (centrezp) at ($(centre)+(AxeMoitie)$) ;
\coordinate (centrezm) at ($(centre)-(AxeMoitie)$) ;

\begin{NouveauPlan}{#4}{#5}{#6}
\draw let \p1=($(centrezp)-(centrezm)$),\n1={atan2(\y1,\x1)} in  ($(centrezp)+(\n1-90:\r)$)
arc[radius=\r,start angle=\n1+270,delta angle=-540];
\end{NouveauPlan}

}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document} 

\begin{tikzpicture}
[x={(0.710cm,-0.410cm)},y={(0cm,0.820cm)},z={(-0.710cm,-0.410cm)}]

% Vecteur Point de Vue
\pgfmathsetmacro{\VpvX}{1}
\pgfmathsetmacro{\VpvY}{1}
\pgfmathsetmacro{\VpvZ}{1}

% Dimensions
\pgfmathsetmacro{\r}{1}     % Rayon du cylindre 
\pgfmathsetmacro{\l}{4}     % Longueur cylindre

\foreach \j in {0,1,...,38}{
    \pgfmathsetmacro{\AngleEntree}{-10*\j}

    \coordinate (centreCardan) at (-20,{-18*\j},5);

    % Circle 
    \begin{scope}[tdplot_screen_coords]
    \draw[red,ultra thick,dashed] (centreCardan) circle (\r);
    \end{scope}

    %Tube
    \coordinate (centrePivVR) at ($(centreCardan)+ ({-5*cos(\AngleEntree)},{-5*sin(\AngleEntree)},0)$);
    %%
    \Pivot{(centrePivVR)}{blue, ultra thick}{ }{cos(\AngleEntree)}{sin(\AngleEntree)}{0}

}


\end{tikzpicture}

\end{document}

Thank you to the braves who will give me some time.

LMT-PhD
  • 1,244
  • 1
    At first sight it looks like the commont error about dimension too large when your draw pictures with large (about multiple meters) dimensions. Your code gives a 563.29cm height. What do you inted to do with this code ? – BambOo May 22 '20 at 14:34
  • I intend to draw a mechanism with different positions and I offset each one 18cm lower, so drawing 5 should hardly go over 100cm, shouldn't it ? – LMT-PhD May 22 '20 at 15:51
  • 1
    Sometimes tikz uses invisible coordinates to construct paths which enlarge the actual bounding box, e.g. B-spline control points, so it is possible this is what is happenning here though it is difficult to be sure. – BambOo May 22 '20 at 16:07
  • 1
    Just to be sure, can you compile your MWE with the 18 multiplicator and \j up to 38 ? Because on my system it compiles fine – BambOo May 22 '20 at 16:13
  • Yes, sorry I had forgotten to uncomment my line \Pivot, which is the problematic one. – LMT-PhD May 22 '20 at 16:51
  • OK, I tried to compile your example, after some test it appears the last centrePivVR is at y-position -15689pt which is pretty close to the internal computational limit of TeX and therefore TikZ. So I guess any computation based on this coordinate (especially involving square roots and others will overflow this limit). Have a look at this post https://tex.stackexchange.com/q/54702/141947 for possible alternatives – BambOo May 24 '20 at 08:54

1 Answers1

1

I have tried to figure out what your code is supposed to do. I understood it somehow, but not completely. The computations in the preamble are not really illuminating.

This being said, I managed to move your sum limit up to 20 which is still too far from the 36 (I imagine for a full circle) you are looking for. The price was to diminish the constant -18 in \coordinate (centreCardan) at (-20, {-18*\j}, 5); to -7. By the way, why do you need -20 for the x coordinate? You could put 0 instead without changing the output.

This brings me to two remarks and an interrogation.

  1. I don't understand why 20 works and 21 doesn't in
  \foreach \j in {0, 1, ..., 20}{
    \pgfmathsetmacro{\AngleEntree}{-10*\j}    
    \coordinate (centreCardan) at (0, {-7*\j}, 5);

The dimension too large error is not given by what you actually draw (see below where I tried to estimate the maximal distance needed for the last drawn elements), but by the computations in \Pivot. As you can see, the drawn elements involve dimensions of about 4000 pt way below the maximal ~16,370.

enter image description here

  1. If we draw everything without moving the point (centreCardan) we obtain something like this.

enter image description here

(I see the "circles" of a spring crushed on a plane which is rolled into a cylinder.)

  1. So, what do you want in the end? I don't think that you want a pdf file long like an Egyptian scroll. I don't see the usefulness of it, but who knows. If the final outcome you want is some sort of animation, then you should create separate images, i.e. move the loop outside the tikzpicture environment. The dimension too large error will disappear.
Daniel N
  • 5,687