来自 pstricks 手册 (p187) 的另一个示例,有什么问题?

来自 pstricks 手册 (p187) 的另一个示例,有什么问题?
\documentclass{article}
\usepackage{pstricks,multido,xkeyval}

\makeatletter

% “TeethNumber”: number of teeth (it must be a divisor of 360!)
\define@key{psset}{TeethNumber}{%
\pst@getint{#1}{\PstCoggedWheel@TeethNumber}}

% “TeethHeight”: height of the teeth, in current unit
\define@key{psset}{TeethHeight}{%
\edef\PstCoggedWheel@TeethHeight{#1}}

% Default parameters values
 \setkeys{psset}{TeethNumber=10,TeethHeight=0.2}

 % Main macro for “cogged wheel” object
 \def\PstCoggedWheel{\def\pst@par{}\pst@object{PstCoggedWheel}}

 \def\PstCoggedWheel@i{{%
 \use@par% Assignment of local parameters
 \pst@cntc=360
 \divide\pst@cntc\PstCoggedWheel@TeethNumber
 % Test to verify if the number of teeth is valid
 \pst@cnth=\pst@cntc
 \multiply\pst@cnth\PstCoggedWheel@TeethNumber
 \ifnum\pst@cnth=360
 \else
 \@pstrickserr{TeethNumber (\PstCoggedWheel@TeethNumber)
 must be a divisor of 360! Results will be inaccurate.}{\@ehpb}%
 \fi
 \pst@cntd=\pst@cntc
 \divide\pst@cntd\tw@
 \pst@dimd=\psunit
 \pssetlength{\pst@dimc}{\PstCoggedWheel@TeethHeight}%
 \advance\pst@dimd-\pst@dimc
 \pscustom{%
 \moveto(\pst@dimd;0)
 \multido{\iAngleA=\z@+\pst@cntc,\iAngleB=\pst@cntd+\pst@cntc,
 \iAngleC=\pst@cntc+\pst@cntc}%
 {\PstCoggedWheel@TeethNumber}{%
 \lineto(1;\iAngleA)
 \lineto(1;\iAngleB)
 \lineto(\pst@dimd;\iAngleB)
 \lineto(\pst@dimd;\iAngleC)}}}}

\makeatother

\begin{document}

 \rput(-4,0){\PstCoggedWheel}
 \rput(-1.5,0){\PstCoggedWheel[TeethNumber=30,TeethHeight=4mm]}
 \rput(4,0){%
      \PstCoggedWheel[unit=2,linecolor=cyan,TeethNumber=36,TeethHeight=0.1]%
 \rput(2.8;200){%
      \PstCoggedWheel[linecolor=green,TeethNumber=18]}}
\end{document} 

答案1

新的包名为pst-wheel

\RequirePackage{filecontents}
\documentclass{article}
\usepackage{pstricks,multido}

\begin{filecontents*}{pst-wheel.sty}
%% Package pst-wheel
\RequirePackage{pstricks}
%
% “TeethNumber”: number of teeth (it must be a divisor of 360!)
\define@key[psset]{}{TeethNumber}[10]{\pst@getint{#1}{\PstCoggedWheel@TeethNumber}}
% “TeethHeight”: height of the teeth, in current unit
\define@key[psset]{}{TeethHeight}[0.2]{\def\PstCoggedWheel@TeethHeight{#1 }}
% Default parameters values
\psset{TeethNumber=10,TeethHeight=0.2}
% Main macro for “cogged wheel” object
\def\PstCoggedWheel{\pst@object{PstCoggedWheel}}
\def\PstCoggedWheel@i{{%
        \use@par% Assignment of local parameters
        \pst@cntc=360
        \divide\pst@cntc\PstCoggedWheel@TeethNumber
        % Test to verify if the number of teeth is valid
        \pst@cnth=\pst@cntc
        \multiply\pst@cnth\PstCoggedWheel@TeethNumber
        \ifnum\pst@cnth=360
        \else
        \@pstrickserr{TeethNumber (\PstCoggedWheel@TeethNumber)
            must be a divisor of 360! Results will be inaccurate.}{\@ehpb}%
        \fi
        \pst@cntd=\pst@cntc
        \divide\pst@cntd\tw@
        \pst@dimd=\psunit
        \pssetlength{\pst@dimc}{\PstCoggedWheel@TeethHeight}%
        \advance\pst@dimd-\pst@dimc
        \pscustom{%
            \moveto(\pst@dimd;0)
            \multido{\iAngleA=\z@+\pst@cntc,\iAngleB=\pst@cntd+\pst@cntc,
                \iAngleC=\pst@cntc+\pst@cntc}%
            {\PstCoggedWheel@TeethNumber}{%
                \lineto(1;\iAngleA)
                \lineto(1;\iAngleB)
                \lineto(\pst@dimd;\iAngleB)
                \lineto(\pst@dimd;\iAngleC)}}}}
\end{filecontents*}

\usepackage{pst-wheel}

\begin{document}

    \rput(-4,0){\PstCoggedWheel}
    \rput(-1.5,0){\PstCoggedWheel[TeethNumber=30,TeethHeight=4mm]}
    \rput(4,0){%
        \PstCoggedWheel[unit=2,linecolor=cyan,TeethNumber=36,TeethHeight=0.1]%
        \rput(2.8;200){%
            \PstCoggedWheel[linecolor=green,TeethNumber=18]}}
\end{document} 

enter image description here

答案2

我使用前面示例中的宏在 p187 上绘制了齿轮。

\documentclass{article}
\usepackage{pstricks,multido}

\makeatletter

\def\PstCoggedWheel#1#2{%
% #1 = number of teeth (it must be a divisor of 360!)
% #2 = height of the teeth, between 0 and 1 unit
\pst@cntc=360
\divide\pst@cntc by #1
\pst@cntd=\pst@cntc
\divide\pst@cntd\tw@
 \pst@dimd=\psunit
 \pssetlength{\pst@dimc}{#2}%
 \advance\pst@dimd-\pst@dimc
 \pscustom{%
 \moveto(\pst@dimd;0)
 \multido{\iAngleA=\z@+\pst@cntc,
 \iAngleB=\pst@cntd+\pst@cntc,
 \iAngleC=\pst@cntc+\pst@cntc}{#1}{%
 \lineto(1;\iAngleA)
 \lineto(1;\iAngleB)
 \lineto(\pst@dimd;\iAngleB)
 \lineto(\pst@dimd;\iAngleC)}}}

\makeatother

\begin{document}

 \rput(-4,0){\PstCoggedWheel{10}{0.2}}
 \rput(-1.5,0){\PstCoggedWheel{30}{4mm}}
 \rput(4,0){%
      \psset{unit=2,linecolor=cyan}\PstCoggedWheel{36}{0.1}}%
 \rput(1.3,-1){%
      \psset{linecolor=green}\PstCoggedWheel{18}{0.2}}
\end{document} 

相关内容