如何獲得一致的鋸齒線?

如何獲得一致的鋸齒線?

我想要獲得一條一致的鋸齒線,用於模仿物理彈簧。

\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}

在下圖中,紅十字代表不一致的鋸齒線,因為其頂端以不同方向的線段開始。

在此輸入影像描述

trunc我透過選擇大量數字來提高精度。但這似乎不起作用。如何解決這個問題?

事實

消除這種不一致的一種方法是選擇一個常數coilwidth。然而,隨著常數的增加,coilwidth動畫看起來不再真實。那就是問題所在。

答案1

最後一招:不要依賴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}

在此輸入影像描述

相關內容