平均能量损失

平均能量损失

如果我取消注释最后一个\rput,我会收到以下错误:

在此处输入图片描述

如何解决这个问题?

平均能量损失

\documentclass[pstricks,border=1cm]{standalone}
\usepackage[nomessages]{fp}

\makeatletter
\def\scale{%
    \psline(100,0)
    \foreach \x in {0,10,...,100}{%
        \pstVerb{/x {\x} bind def 
                        /y {dup 100 mod 0 eq {-18} {dup 50 mod 0 eq {-9} {-3} ifelse} ifelse} bind def}%
        \psline(!x y)(!x y neg)
        }%
}

\def\caliper#1{%
    \psset{xunit=1mm,yunit=2pt,linewidth=3pt}
    \pspicture(0,-20)(100,20)
        \scale
        \rput(#1,0){\psset{xunit=.9\psxunit,yunit=.5\psyunit,linecolor=red,linewidth=.5\pslinewidth}\scale}%
        \FPeval\Label{trunc(#1/10:1)}
        %\rput(50,15){$\Label$} % this line causes an error!
    \endpspicture
}

\begin{document}
\foreach \i in {0,...,10}{\caliper{\i}}
\end{document}

答案1

用定义/y和不是一个好主意。它们是全局的,会导致内部值错误。 /x\pstVerb

\documentclass[pstricks,border=1cm]{standalone}
\usepackage{pst-calculate}
\def\scale{%
    \psline(100,0)
    \foreach \x in {0,10,...,100}{%
        \pstVerb{/xCoor {\x} bind def 
            /yCoor {dup 100 mod 0 eq {-18} 
                    {dup 50 mod 0 eq {-9} {-3} ifelse} ifelse} bind def
            }%
        \psline(!xCoor yCoor)(!xCoor yCoor neg)
}}

\def\caliper#1{%
    \psset{xunit=1mm,yunit=2pt,linewidth=3pt}
    \pspicture(0,-20)(100,20)
    \rput(#1,0){\psset{xunit=.9\psxunit,yunit=.5\psyunit,
            linecolor=red,linewidth=.5\pslinewidth}\scale}%
    \scale
    \rput(50,15){\psCalculate[round-integer-to-decimal,
                      round-precision=1,round-mode=places]{#1/10}}
    \endpspicture}

\begin{document}
    \foreach \i in {0,1,...,10}{\caliper{\i}}
\end{document}

答案2

尝试这个:

\documentclass[pstricks,border=1cm]{standalone}
\usepackage[nomessages]{fp}

\makeatletter
\def\scale{%
    \psline(100,0)
    \foreach \x in {0,10,...,100}{%
        \pstVerb{/x {\x} bind def
                        /y {dup 100 mod 0 eq {-18} {dup 50 mod 0 eq {-9} {-3} ifelse} ifelse} bind def}%
        \psline(!x y)(!x y neg)
        }%
}

\def\caliper#1{%
    \FPeval{\Label}{trunc(#1/10:1)}%
    \psset{xunit=1mm,yunit=2pt,linewidth=3pt}
    \pspicture(0,-20)(100,20)
        \rput(50,15){$\Label$}%
        \scale
        \rput(#1,0){\psset{xunit=.9\psxunit,yunit=.5\psyunit,linecolor=red,linewidth=.5\pslinewidth}\scale}%
    \endpspicture
}

\begin{document}
\foreach \i in {0,...,10}{\caliper{\i}}
\end{document}

在此处输入图片描述

相关内容