9

There's something strange going on with the animation at 135 degrees. I can't figure out what's going wrong.

enter image description here

Here's the MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{animate}
\newcommand{\crankshaft}[1]{%
        \begin{tikzpicture}[x=0.5cm,y=0.5cm]

            \draw[fill]  (0,0) coordinate [label=180:Z] (Z) circle (2pt);           %% center of the picture
            \draw[fill]  (5,5) coordinate [label=135:Q] (Q) circle (2pt);           %% center of the circle
            \draw[fill]  (Q) -- +(  0:6)   coordinate [label=0:A] (A) circle (2pt); %% first point on the circle
            \clip[draw] (Q)  circle (4.5cm);
            \draw[help lines,blue!20,step=1] (0,0) grid (12,12);
            %% drawing the circle
            \draw[blue]  (A) 
                         let \p1 = ($ (A) - (Q) $) in
                         arc(0:360:{veclen(\x1,\y1)});

            \draw [line width=0.4pt,red]
                  let \p1 = ($(A) - (Q)$), \n1={veclen(\x1,\y1)} in
                  (Q) -- +(#1:\n1)
                  coordinate (B) circle (2pt);

            \draw[purple,line width=0.4pt] 
                  (B) -- +($  (0,0) ! 2em ! 0 : ($(B)-(Q)$)  $)  
                  coordinate [label=center:{\textbf{B:#1}}] (Bl) circle (2em);

            \draw[blue]   
                  ($ (B) ! 0.45 ! (Q) $) 
                  coordinate (tC) circle (2pt);

            \draw[line width=01.5em,->]
                  (tC) 
                  let \p1 = ($(tC) - (Q)$), 
                      \n1={atan2(\x1,\y1)}, %% start angle
                      \n2={\n1+90},         %% end angle
                      \n3={veclen(\x1,\y1)} %% radius
                  in
                      arc (\n1:\n2:\n3)
                      -- ++(\n2+80:1em)
                     ;
        \end{tikzpicture}%
}

\begin{document}

    \begin{animateinline}[autoplay,loop]{1}
    \multiframe{24}{iAng=0+15}{%
        \crankshaft{\iAng}%
    }%
    \end{animateinline}

\end{document}
A.Ellett
  • 50,533
  • Hm, interesting. Anyway, why don’t you just use #1 for \n1? You probably could also simplify a lot more … – Qrrbrbirlbel Feb 17 '13 at 03:15
  • @GarbageCollector. What did you do to get the animation to work? – A.Ellett Feb 17 '13 at 03:41
  • @A.Ellett: I created a PDF containing a series of frames (each frame in a single page) and converted it to a GIF format. – kiss my armpit Feb 17 '13 at 03:45
  • @GarbageCollector. How did you get a GIF version? – A.Ellett Feb 17 '13 at 03:49
  • To get a GIF version, please visit my answer here or here. – kiss my armpit Feb 17 '13 at 03:50
  • @Qrrbrbirlbel. I could just use #1 for \n1 in this answer, but that solution will not work later on. I want to have a piston and some gears attached in a manner that certain "wheels" will be turn at different speeds. So your suggestion, while it will work here, won't work for what I'm ultimately after. – A.Ellett Feb 17 '13 at 04:59
  • 1
    @A.Ellett (You might remove the animating bit as it has nothing to do with problem.) The culprit seems to be the divide function of PGF math. Check the output of \pgfmathparse{33.19675/-33.19678}\pgfmathresult and vary the divisor’s last digit. It jumps from -1.0 (last digit: 5) to -0.1 (6 to 8) to -0.99998 (9). – Qrrbrbirlbel Feb 17 '13 at 05:22
  • @Qrrbrbirlbel Thanks for that comment (+1). I was about to write that too. I suggest the title of the question should also be changed. –  Feb 17 '13 at 06:46
  • 1
    @Qrrbrbirlbel This bug is fixed in the current CVS version of TikZ/PGF. – Paul Gaborit Feb 17 '13 at 08:32
  • 1
    @PaulGaborit You are right. The \pgfmathdivide@@ macro has been patched (with the help of a few others). Changelog of 2011-04-18. @A.Ellett Maybe it is time for you to update to the CVS version after all … – Qrrbrbirlbel Feb 17 '13 at 08:42
  • @Qrrbrbirlbel. Then I've got a few quetions. If the patch is so old, why isn't already a part of the most up-to-date LaTeX? Secondly, and of more concern, how do I download it without breaking everything? Does the download just do what it needs to do if my LaTeX is installed properly? Is there some place on this site that'll walk me through what to do? – A.Ellett Feb 17 '13 at 15:26
  • @A.Ellett (The . after my username prevents me to get notified.) Because the patch is only in the CVS but not in the official release that get carried out to CTAN. The official release does not get updated that much. Take a look at … do I install CVS version, and how? and install it in your local texmf tree. – Qrrbrbirlbel Feb 18 '13 at 00:43
  • @Qrrbrbirlbel if you put your comments together, I'd accept that as an answer. – A.Ellett Feb 18 '13 at 00:51

1 Answers1

3

There is no angle discontinuity in PSTricks.

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\usepackage{siunitx}
\usepackage{multido}
\addtopsstyle{gridstyle}
{
    griddots=0,
    gridwidth=0.2pt,
    gridcolor=blue!20,
    subgriddiv=5,
    subgridwidth=0.2pt,
    subgridcolor=blue!20,
    gridlabels=0pt,
}

\begin{document}
\multido{\i=0+15}{24}{%
\begin{pspicture}(-4,-4)(4,4)
    \psgrid[style=gridstyle](-2,-2)(2,2)
    \pstGeonode[PosAngle={135,0,180}]
        (0,0){Q}
        (1.8,0){A}
        (-2,-2){Z}
    \pstCircleOA[linecolor=blue!50]{Q}{A}
    \pscircle(Q){3.8}
    \pstGeonode[PointName=none,PointSymbol=none]
        (1;\i){Tail}
        (!1 \i\space 45 add PtoC){Head}
        ([nodesep=2.8]{Tail}Q){C}
    \psarc[arrowscale=0.9,linewidth=3\pslinewidth]{->}(Q){1}{(Tail)}{(Head)}
    \psset{linecolor=red}
    \pscircle(C){1}
    \psline(Q)(C)
    \rput*(C){\textcolor{red}{B:\ang{\i}}}
\end{pspicture}}
\end{document}
  • 4
    There is no TikZ in PSTricks. ;) – Qrrbrbirlbel Feb 17 '13 at 04:47
  • 1
    I love the answer, but unfortunately I already know how to do this in pstricks. My objective was to learn how to use tikz. Nevertheless, great answer! – A.Ellett Feb 17 '13 at 04:57
  • Actually, there's a bit of syntax in your answer I'm not familiar with. What are you doing when you write ([nodesep=2.8]{Tail}Q}{C}? Actually, I can see it's a translation, but where is it documented? – A.Ellett Feb 17 '13 at 05:52
  • @A.Ellett: It represents a node which is 2.8 apart from Q node in the direction of a vector from Q node to Tail node. It is documented in pstricks-doc.pdf on page 147. Use texdoc pstricks-doc to open the documentation. – kiss my armpit Feb 17 '13 at 06:44