10

I want to make my \protractor can accept points in all available format defined in PSTricks. How to do this?

\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}

enter image description here

2
  • 3
    Is the tikz-pgf tag there for a specific reason? This doesn’t look like such a broad question. Sep 20, 2013 at 19:12
  • @Qrrbrbirlbel: There is no specific reason. It was just a typo. :-) Sep 21, 2013 at 16:24

2 Answers 2

7
\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}

enter image description here

11
+250

You can draw a node connection with \pcline, and position your protractor at one end of this connection with \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}

Result:

enter image description here

Alternatively you can use the \pst@getcoor macro to extract the node coordinates:

\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}
2
  • How about adding an optional argument to \protractor as Herbert did in his answer? Sep 21, 2013 at 1:59
  • 1
    @PGFTricks See the edited answer.
    – Christoph
    Sep 21, 2013 at 6:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .