如何使我的量角器能够接受点和节点?

如何使我的量角器能够接受点和节点?

我想让我的\protractor积分能够接受 PSTricks 中定义的所有可用格式。该怎么做?

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor
\usepackage{pst-node,multido}

\makeatletter
\def\@protractor#1{%
    \psset{dimen=middle,linewidth=.5\pslinewidth}
    \pscustom{\psarc(0,0){#1}{0}{180}\psline(-#1,-.3)(#1,-.3)\closepath}
    \multido{\na=0+90}{3}{\psline(!#1 .725 mul \na\space PtoC)}
    \multido{\ns=0+1}{180}{\psline(!#1 .975 mul \ns\space PtoC)(#1;\ns)}
    \multido{\nm=0+5}{37}{\psline(!#1 .950 mul \nm\space PtoC)(#1;\nm)}
    \multido{\nl=0+10}{19}{%
        \psline(!#1 .925 mul \nl\space PtoC)(#1;\nl)
        \uput{!#1 .850 mul}[\nl]{!\nl\space 90 sub}(0,0){\small$\nl$}
        \uput{!#1 .775 mul}[!180 \nl\space sub]{!90 \nl\space sub}(0,0){\small$\nl$}
        \psline(!#1 .05 mul \nl\space PtoC)(!#1 .725 mul \nl\space PtoC)
    }}

\def\protractor(#1,#2)(#3,#4)#5{%
    \rput(#3,#4){%
        \rput{!#2 #4 sub #1 #3 sub atan 180 add}(0,0){%
            \@protractor{#5}}}}

\makeatother

\begin{document}
\begin{pspicture}[showgrid=true](-5,-5)(10,5)
    \protractor(-2,1)(3,-2){5}
    \pcline[nodesep=-2,linecolor=blue](-2,1)(3,-2)
    \psdots(-2,1)(3,-2)
\end{pspicture}
\end{document}

在此处输入图片描述

答案1

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

\makeatletter
\def\protractor@ii#1{%
    \psset{dimen=middle,linewidth=.5\pslinewidth}
    \pscustom{\psarc(0,0){#1}{0}{180}\psline(-#1,-.3)(#1,-.3)\closepath}
    \multido{\na=0+90}{3}{\psline(!#1 .725 mul \na\space PtoC)}
    \multido{\ns=0+1}{180}{\psline(!#1 .975 mul \ns\space PtoC)(#1;\ns)}
    \multido{\nm=0+5}{37}{\psline(!#1 .950 mul \nm\space PtoC)(#1;\nm)}
    \multido{\nl=0+10}{19}{%
        \psline(!#1 .925 mul \nl\space PtoC)(#1;\nl)
        \uput{!#1 .850 mul}[\nl]{!\nl\space 90 sub}(0,0){\small$\nl$}
        \uput{!#1 .775 mul}[!180 \nl\space sub]{!90 \nl\space sub}(0,0){\small$\nl$}
        \psline(!#1 .05 mul \nl\space PtoC)(!#1 .725 mul \nl\space PtoC)%
    }}

\def\protractor{\pst@object{protractor}}% read * and [] and runs \<object>@i 
\def\protractor@i(#1)(#2)#3{%
  \begin@SpecialObj
  \pnodes(#1){node@1}(#2){node@2}%
  \rput(node@2){%
     \rput{! \psGetNodeCenter{node@1} \psGetNodeCenter{node@2} 
      [email protected] [email protected] sub [email protected] [email protected] sub atan }(0,0){\protractor@ii{#3}}}%
  \end@SpecialObj}

\makeatother

\begin{document}
\begin{pspicture}[showgrid=true](-5,-5)(10,5)
    \pnodes(-2,1){A}(3,-2){B}
    \protractor[linecolor=red](A)(3,-2){5}
    \pcline[nodesep=-2,linecolor=blue](-2,1)(3,-2)
    \psdots(A)(B)
\end{pspicture}
\end{document}

在此处输入图片描述

答案2

您可以使用 绘制节点连接\pcline,并使用 将量角器定位在该连接的一端\ncput

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor
\usepackage{pst-node,multido}

\makeatletter
\def\@protractor#1{%
    \psset{dimen=middle,linewidth=.5\pslinewidth}
    \pscustom{\psarc(0,0){#1}{0}{180}\psline(-#1,-.3)(#1,-.3)\closepath}
    \multido{\na=0+90}{3}{\psline(!#1 .725 mul \na\space PtoC)}
    \multido{\ns=0+1}{180}{\psline(!#1 .975 mul \ns\space PtoC)(#1;\ns)}
    \multido{\nm=0+5}{37}{\psline(!#1 .950 mul \nm\space PtoC)(#1;\nm)}
    \multido{\nl=0+10}{19}{%
        \psline(!#1 .925 mul \nl\space PtoC)(#1;\nl)
        \uput{!#1 .850 mul}[\nl]{!\nl\space 90 sub}(0,0){\small$\nl$}
        \uput{!#1 .775 mul}[!180 \nl\space sub]{!90 \nl\space sub}(0,0){\small$\nl$}
        \psline(!#1 .05 mul \nl\space PtoC)(!#1 .725 mul \nl\space PtoC)
    }}
\def\protractor{\pst@object{protractor}}
\def\protractor@i(#1)(#2)#3{%
   \begin@SpecialObj
   \pcline[linestyle=none](#1)(#2)
   \ncput[nrot=:U, npos=1]{\@protractor{#3}}%
   \end@SpecialObj}
\makeatother

\begin{document}
\begin{pspicture}[showgrid=true](-5,-5)(10,5)
    \protractor[linecolor=green!70!black](! 2 neg 1)(5;-10){5}
    \pcline[nodesep=-2,linecolor=blue](! 2 neg 1)(5;-10)
    \psdots(! 2 neg 1)(5;-10)
\end{pspicture}
\end{document}

结果:

在此处输入图片描述

或者,您可以使用\pst@getcoor宏来提取节点坐标:

\def\protractor{\pst@object{protractor}}
\def\protractor@i(#1)(#2)#3{%
   \begin@SpecialObj
   \pst@getcoor{#1}\pst@tempA%
   \pst@getcoor{#2}\pst@tempB%
   \rput(!\pst@tempB\tx@UserCoor){%
      \rput{! \pst@tempA \pst@tempB 
              3 -1 roll exch sub 
              3 1 roll sub atan 180 add}(0,0){%
              \@protractor{#3}}}
   \end@SpecialObj}

相关内容