我想制作一个带有弹簧的动画。必须保持弹簧的缠绕恒定才能制作出更逼真的动画。
以下 MWE 说明了\pszigzag
无法产生具有可靠恒定绕组的线圈的当前情况。我7
为绕组设置了(一个素数),但输出振荡;输出绕组有时为 6.5,有时为 7。红色箭头还显示端角从上到下变化。请仔细查看下图并进行比较。
\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}
是否可以得到匝数稳定的线圈?
答案1
您应该截断而不是四舍五入Factor
:
\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}
答案2
\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}
答案3
四舍五入到小数点后第六位也可以解决这个问题。
\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}