[pstricks] npos with absolute values?
Herbert Voss
LaTeX at zedat.fu-berlin.de
Wed Oct 19 06:52:08 CEST 2005
Christoph Bersch wrote:
> Hi!
>
> Is there a possibility to use npos with absolute values?
>
> I have for example two nodes with a line between them and want to label
> the connection at a fixed distance from one node, that means in the
> following examples I would like something like
>
> \ncput[npos=2cm]{Test}
>
> instead of the relative positioning
needs a new macro ...
Herbert
\documentclass{article}
\usepackage{pst-plot,pst-node}
\SpecialCoor
\makeatletter
\def\setLNode(#1)(#2)#3#4{%
\pst at getcoor{#1}\pst at tempA%
\pst at getcoor{#2}\pst at tempB%
\pssetlength\pst at dima{#3}%
\pnode(!%
\pst at tempA /YA exch \pst at number\psyunit div def
/XA exch \pst at number\psxunit div def
\pst at tempB /YB exch \pst at number\psyunit div def
/XB exch \pst at number\psxunit div def
/dx XB XA sub def
/dy YB YA sub def
/angle dy dx Atan def
/length \pst at number\pst at dima \pst at number\psunit div def
XA length angle cos mul add YA length angle sin mul add ){#4}%
}
\def\nlput{\@ifnextchar[\nlput at i{\nlput at i[]}}
\def\nlput at i[#1](#2)(#3)#4#5{{%
\pst at killglue
\psset{#1}%
\setLNode(A)(B){#4}{@temp}
\pcline[linestyle=none](#2)(@temp)%
\ncput[npos=1]{#5}%
}}
\makeatother
\begin{document}
\begin{pspicture}(5,2)
\pnode(0,0){A}
\pnode(5,2){B}
\ncline{A}{B}
\nlput[nrot=:U](A)(B){1cm}{Test}
\nlput[nrot=:U](A)(B){2cm}{Test}
\nlput[nrot=:U](A)(B){3cm}{Test}
\nlput[nrot=:U](A)(B){4cm}{Test}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list