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}
13
  • Hm, interesting. Anyway, why don’t you just use #1 for \n1? You probably could also simplify a lot more … Feb 17 '13 at 3:15
  • @GarbageCollector. What did you do to get the animation to work?
    – A.Ellett
    Feb 17 '13 at 3:41
  • 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). Feb 17 '13 at 5:22
  • 1
    @Qrrbrbirlbel This bug is fixed in the current CVS version of TikZ/PGF. Feb 17 '13 at 8: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 … Feb 17 '13 at 8:42
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
  • 4
    There is no TikZ in PSTricks. ;) Feb 17 '13 at 4: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 4: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 5: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. Feb 17 '13 at 6:44

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.