13

I want to create an animation with a spring. The winding must be kept constant to make more realistic animation.

The following MWE illustrates the current situation of \pszigzag where it cannot produce a coil with reliable constant winding. I set 7 (a prime number) for the winding but the output oscillates; the output windings are sometimes 6.5 and sometimes 7. The red arrows also show the end corners changing from up to down. Please carefully see the image below and compare among them.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-coil,multido}
\usepackage[nomessages]{fp}

\FPset\CoilArm{0.5}
\FPset\CoilWidth{.5}
\FPset\Windings{7}


\psset{coilarm=\CoilArm,coilwidth=\CoilWidth,linecolor=blue,linewidth=2\pslinewidth}

\def\SetFactorByLength#1{% #1: total length includes the arms
    \FPeval\Factor{round((#1-2*CoilArm)/(CoilWidth*Windings):3)}\ignorespaces
}

\begin{document}
\begin{pspicture}[showgrid](15,-11)
    \multido{\ix=5+1,\iy=-1+-1}{10}{%
    \SetFactorByLength{\ix}
    \pszigzag[coilheight=\Factor](0,\iy)(\ix,\iy)}
\end{pspicture}
\end{document}

Is it possible to get a coil with stable number of windings?

9

You should be truncating, not rounding the quantity in Factor:

Sample output

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-coil,multido}
\usepackage[nomessages]{fp}

\FPset\CoilArm{0.5}
\FPset\CoilWidth{.5}
\FPset\Windings{7}


\psset{coilarm=\CoilArm,coilwidth=\CoilWidth,linecolor=blue,linewidth=2\pslinewidth}

\def\SetFactorByLength#1{% #1: total length includes the arms
    \FPeval\Factor{trunc((#1-2*CoilArm)/(CoilWidth*Windings):3)}\ignorespaces
}

\begin{document}
\begin{pspicture}[showgrid](15,-11)
    \multido{\ix=5+1,\iy=-1+-1}{10}{%
    \SetFactorByLength{\ix}
    \pszigzag[coilheight=\Factor](0,\iy)(\ix,\iy)}
\end{pspicture}
\end{document}
6
\documentclass[pstricks]{standalone}
%\usepackage[pdf]{pstricks}% for pdflatex --shell-escape
\usepackage{pst-plot,pst-coil}
\begin{document}

\psset{coilarm=2mm,amplitude=0.5}
\multido{\rA=1+0.2}{20}{%
\begin{pspicture}(-0.5,0.75)(1.25,-5)
\psrotateright{%
\psaxes[linecolor=black!20,tickcolor=black!20,
        labelFontSize=\scriptscriptstyle]{->}(5mm,0)(4.5,1)
\pssin[periods=4,linecolor=red](0,0.5)(\rA,0.5)}%
\end{pspicture}}
\multido{\rA=5+-0.2}{20}{%
\begin{pspicture}(-0.5,0.75)(1.25,-5)
\psrotateright{%
\psaxes[linecolor=black!20,tickcolor=black!20,
        labelFontSize=\scriptscriptstyle]{->}(5mm,0)(4.5,1)
\pssin[periods=4,linecolor=red](0,0.5)(\rA,0.5)}%
\end{pspicture}}
\end{document}

enter image description here

  • Thank you for giving the alternate but I think Andrew Swann's answer suits my question best. – kiss my armpit Apr 21 '13 at 13:36
1

Rounding for the sixth decimal place can also fix this issue.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-coil,multido}
\usepackage[nomessages]{fp}

\FPset\CoilArm{0.5}
\FPset\CoilWidth{.5}
\FPset\Windings{7}


\psset{coilarm=\CoilArm,coilwidth=\CoilWidth,linecolor=blue,linewidth=2\pslinewidth}

\def\SetFactorByLength#1{% #1: total length includes the arms
    \FPeval\Factor{round((#1-2*CoilArm)/(CoilWidth*Windings):6)}\ignorespaces
}

\begin{document}
\begin{pspicture}[showgrid](15,-11)
    \multido{\ix=5+1,\iy=-1+-1}{10}{%
    \SetFactorByLength{\ix}
    \pszigzag[coilheight=\Factor](0,\iy)(\ix,\iy)}
\end{pspicture}
\end{document}

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.