PSTricks 绘图变量不精确

PSTricks 绘图变量不精确

请考虑以下示例:

\documentclass{article}

\usepackage{pst-coil}

\psset{dimen = middel}

\def\frekvensgenerator[#1,#2](#3,#4){
  \psframe(#3,#4)(!#3 #1 add #4 #2 add)
  \psline(!#3 #4 #2 2 div add)(!#3 #1 add #4 #2 2 div add)
  \psframe(!#3 #1 2 div add 0.2 sub #4)(!#3 #1 2 div add 0.2 add #4 #2 2 div add)
  \rput{270}(!#3 #1 2 div add #4){%
    \psCoil[
      linewidth = 1.5pt,
      coilwidth = \spolevidde,
      coilheight = \spolehoejde,
      coilarm = 0
    ]{0}{\drejning}%
  }
  \psframe[
    fillstyle = solid,
    fillcolor = yellow!70
  ](!#3 #1 2 div add 0.25 sub  #4 \drejning\space 480 div \spolevidde\space mul \spolehoejde\space mul sub 1 sub)(!#3 #1 2 div add 0.25 add  #4 \drejning\space 480 div \spolevidde\space mul \spolehoejde\space mul sub)
  \psline(!#3 #1 2 div add #4 \drejning\space 480 div \spolevidde\space mul \spolehoejde\space mul sub 1 sub)(!#3 #1 2 div add #4 \drejning\space 480 div \spolevidde\space mul \spolehoejde\space mul sub 3 sub)
}

\begin{document}

\def\spolevidde{0.5}
\def\spolehoejde{0.5}

\begin{pspicture}(3.5,6.2)
\def\drejning{810}
  \frekvensgenerator[1.5,1.5](0,4.7)
\def\drejning{3330}
  \frekvensgenerator[1.5,1.5](2,4.7)
\end{pspicture}

\end{document}

输出

从中可以看出,如果我改变弹簧扭转的总度数,重量就不会连接到弹簧上的同一点(模数为绕组的整数倍)。

我如何实现这个目标?

PS 如果代码可以变得更简单(几乎肯定可以),非常欢迎您改进它。:)

答案1

\documentclass{article}
\usepackage{pst-coil}
%\psset{dimen = middel}

\def\frekvensgenerator[#1,#2](#3,#4)#5{%
  \psframe(#3,#4)(!#3 #1 add #4 #2 add)
  \psline(!#3 #4 #2 2 div add)(!#3 #1 add #4 #2 2 div add)
  \psframe(!#3 #1 2 div add 0.2 sub #4)(!#3 #1 2 div add 0.2 add #4 #2 2 div add)
  \rput{270}(!#3 #1 2 div add #4){%
    \psCoil[
      linewidth = 1.5pt,
      coilwidth = \spolevidde,
      coilheight = \spolehoejde,
      coilaspect=45,
    ]{0}{#5}%
  }%
  \psframe[fillstyle = solid,fillcolor = yellow!70]%
    (!#3 #1 2 div add 0.25 sub #4 #5 360 div \dxCoil mul sub 1 sub)%
    (!#3 #1 2 div add 0.25 add #4 #5 360 div \dxCoil mul sub  )
  \psline(!#3 #1 2 div add #4 #5 360 div \dxCoil mul sub 1 sub)%
    (!#3 #1 2 div add #4 #5 360 div \dxCoil mul sub 3 sub)%
}

\begin{document}
\def\spolevidde{0.5 }
\def\spolehoejde{0.5 }
\edef\dxCoil{ \spolehoejde \spolevidde mul 45 sin mul }

\begin{pspicture}(3.5,6.2)
  \frekvensgenerator[1.5,1.5](0,4.7){810}
  \frekvensgenerator[1.5,1.5](2,4.7){3330}
  \frekvensgenerator[1.5,1.5](4,4.7){6930}
\end{pspicture}

\end{document}

在此处输入图片描述

45 sin是 3D 视图所需要的。线圈在 45 度角下可见,这是 的值coilaspect,默认情况下为45。但是,我想您正在寻找类似以下内容的内容:

\documentclass{article}
\usepackage{pst-coil}

\makeatletter
\def\frekvensgenerator{\@ifnextchar[\frekvensgenerator@i{\frekvensgenerator[1.5,1.5]}}
\def\frekvensgenerator@i[#1,#2](#3,#4)#5{%
  \psframe(#3,#4)(!#3 #1 add #4 #2 add)
  \psline(!#3 #4 #2 2 div add)(!#3 #1 add #4 #2 2 div add)
  \psframe(!#3 #1 2 div add 0.2 sub #4)(!#3 #1 2 div add 0.2 add #4 #2 2 div add)
  \pnode(!#3 #1 2 div add #4){StartX}
  \psline[linewidth=1.5pt](StartX)(StartX|{!0 #4 \spolearm sub})
  \rput{270}(StartX|{!0 #4 \spolearm sub \dxCoil 2 div sub}){%
    \psCoil[
      linewidth = 1.5pt,
      coilwidth = \spolevidde,
      coilheight = \spolehoejde,
    ]{-90}{#5}%
  }%
  \psline[linewidth = 1.5pt]%
    (StartX|{!0 #4 #5 90 sub 360 div \dxCoilRel mul sub \spolearm sub \dxCoil sub})%
    (StartX|{!0 #4 #5 90 sub 360 div \dxCoilRel mul sub \spolearm dup add sub \dxCoil sub})
  \psframe[fillstyle = solid,fillcolor = yellow!70]%
    (!#3 #1 2 div add 0.25 sub #4 
      #5 90 sub 360 div \dxCoilRel mul sub \spolearm dup add sub \dxCoil sub)%
    (!#3 #1 2 div add 0.25 add #4 
      #5 90 sub 360 div \dxCoilRel mul sub \spolearm dup add sub \dxCoil sub 1 sub)
  \pnode(StartX|{!0 #4 #5 90 sub 360 div \dxCoilRel mul sub 
                  \spolearm dup add sub \dxCoil sub 3 sub}){End#3}
  \psline(StartX|{!0 #4 #5 90 sub 360 div \dxCoilRel mul sub 
                   \spolearm dup add sub \dxCoil sub 1 sub})(End#3)%
}
\makeatother
\begin{document}
\def\spolearm{0.2 }
\def\spolevidde{0.5 }
\def\spolehoejde{0.3 }
\def\dxCoil{ \spolehoejde \spolevidde mul }
\def\dxCoilRel{ \dxCoil 45 sin mul }

\begin{pspicture}(3.5,6.2)
  \frekvensgenerator(0,4.7){3690}
  \def\spolevidde{0.45 }\def\spolehoejde{0.6 }
  \frekvensgenerator(2,4.7){3690}
  \def\spolevidde{0.4 }\def\spolehoejde{1.2 }
  \frekvensgenerator(4,4.7){3690}
  \def\spolevidde{0.35 }\def\spolehoejde{2.4 }
  \frekvensgenerator(6,4.7){3690}
  \pscurve[linecolor=red,linewidth=1.5pt](End0)(End2)(End4)(End6)
\end{pspicture}

\end{document}

在此处输入图片描述

动画如下:

在此处输入图片描述

答案2

pszigzag提供的pst-coil似乎不可靠,因此我创建了自己的锯齿形,如下所示。

创建动画时确保\CoilWidth所有帧都不会变为负数。

\FPeval\CoilWidth{1-1.4*Lambda}% make sure it never becomes negative, otherwise the orientation will change!

平均能量损失

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

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

\psset
{
    dimen=medusa,
    fillcolor=yellow,
    linejoin=1,
}

\def\System#1{% #1: total length includes the arms
    \FPeval\Lambda{(#1-2*CoilArm)/Windings}%
    \FPeval\CoilWidth{1-1.4*Lambda}% make sure it never becomes negative, otherwise the orientation will change!
    \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}%
    \rput(-.5,0){\psframe(1,1)\psframe(1,.5)\psframe(!1 3 div 0)(!2 3 div .5)}%
    \pscustom
    {
        \psline(0,0)
        \psnline(0,\Pnodecount){P}
        \psline(0,-#1)
    }%
    \rput(!-.25 -#1 1 sub){\psframe[fillstyle=solid](.5,1)\psline(.25,0)(.25,-2)}%
    \ignorespaces
}

\def\func(#1){2*sin(2*pi*#1/1)+4}

\begin{document}
\multido{\n=.00+.05}{21}{%
\begin{pspicture}(1,-9)(3,1)
    \rput(2,0){\FPeval\y{\func(\n)}\System{\y}}
\end{pspicture}}
\end{document}

在此处输入图片描述

相关内容