Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to get a consistent zigzag line that will be used to mimic a physical spring.

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

\FPset\CoilArm{.2}
\FPset\Windings{7}

\psset
{
    coilarm=\CoilArm,
    linejoin=1,
}

\def\System#1#2{% #1: total length includes the arms, #2: coil width
    \FPeval\CoilWidth{trunc(#2,9)}%
    \FPeval\CoilHeight{trunc((#1-2*CoilArm)/(CoilWidth*Windings),9)}%
    \pszigzag[coilwidth=\CoilWidth,coilheight=\CoilHeight](1,0)(1,-#1)%
    \ignorespaces
}

\begin{document}

\begin{pspicture}(13,-7)
\multido{\nx=0+1.25,\nl=2.50+.50,\nw=1.00+-0.10}{10}{\rput(\nx,0){\System{\nl}{\nw}}}
\end{pspicture}
\end{document}

In the figure below, the red cross represents inconsistent zigzag lines as its top end begins with a different orientation of segment.

enter image description here

I have increased the precision of trunc by choosing a large number of digit. But it does not seem to work. How to solve this issue?

Facts

One method to get rid of this inconsistency is by choosing a constant coilwidth. However, with constant coilwidth the animation will not look realistic anymore. That is the problem.

share|improve this question
    
The orientation seems to be consistent at the end of the coil. So, you could reverse the coil drawing. However, my guess is your question will then change to request a consistent coil from either end... –  Werner Dec 28 '13 at 16:18
    
@Werner: Yes. I know that but they are still inconsistent and it will make a bad animation. –  stalking is prohibited Dec 28 '13 at 16:21

1 Answer 1

up vote 3 down vote accepted

The last resort: don't rely on pst-coil!

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

\FPset\CoilArm{.6}
\FPset\Windings{7}

\def\System#1#2{% #1: total length includes the arms, #2: coil width
    \FPeval\CoilWidth{#2}%
    \FPeval\Lambda{(#1-2*CoilArm)/Windings}%
    \FPeval\PlotPoints{trunc(4*Windings+1,0)}%
    \curvepnodes[plotpoints=\PlotPoints,algebraic]{0}{\Lambda\space \Windings\space mul}{\CoilWidth*sin(2*Pi*t/\Lambda)|-t-\CoilArm}{P}%
    \pscustom[linejoin=1]
    {
        \psline(0,0)
        \psnline(0,\Pnodecount){P}
        \psline(0,-#1)
    }%
    \ignorespaces
}

\begin{document}

\begin{pspicture}(13,-7)
\multido{\nx=1.00+1.25,\nl=2.50+.50,\nw=.50+-.05}{10}{\rput(\nx,0){\System{\nl}{\nw}}}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
    
\CoilWidth which is used as the amplitude must be kept positive to avoid getting inconsistent zigzag. It might be the source of problem in pszigzag (just my hypothesis). –  stalking is prohibited Dec 28 '13 at 21:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.