[pstricks] How can I get the x and y coordinates of a node?

Denis Girou Denis.Girou at idris.fr
Wed Oct 24 20:02:29 CEST 2001


>>>>> "Henrik.Bengtsson" == Henrik Bengtsson <hb at maths.lth.se> writes:

    Henrik.Bengtsson> Dear PSTricks coders, is it possible to get the x and y coordinates
    Henrik.Bengtsson> of a node? I would like to get this to be able to calculate new
    Henrik.Bengtsson> coordinates that are relative to a certain node coordinates.
 
    Henrik.Bengtsson> For example, I would like to calculate the midpoint between two nodes A
    Henrik.Bengtsson> and B:
 
    Henrik.Bengtsson> \usepackage{pst-all} \usepackage{calc}
 
    Henrik.Bengtsson> \newlength{\newx} \newlength{\newy} \psset{xunit=10mm,yunit=10mm}
    Henrik.Bengtsson> \begin{pspicture}(0,0)(5,5)
    Henrik.Bengtsson>   \rput(2,4){\circlenode{A}{A}}
    Henrik.Bengtsson>   \rput(4,4){\circlenode{B}{B}}
    Henrik.Bengtsson>   \ncline{A}{B}
 
    Henrik.Bengtsson>   \setlength{\newx}{(\getxcoord{A} + \getxcoord{B}) / 2}
    Henrik.Bengtsson>   \setlength{\newy}{(\getycoord{A} + \getycoord{B}) / 2}
 
    Henrik.Bengtsson>   % Midpoint between A and B
    Henrik.Bengtsson>   \pnode(\newx,\newy){AB}
 
    Henrik.Bengtsson>   % Line to a node 2 yunits below the midpoint
    Henrik.Bengtsson>   \psaddtolength{\newy}{-2}
    Henrik.Bengtsson>   \rput(\newx,\newy){\circlenode{C}{C}}})
    Henrik.Bengtsson>   \ncline{AB}{C}
    Henrik.Bengtsson> \end{pspicture}
 
    Henrik.Bengtsson> Is there a "\getxcoord" and a "\getycoord" or something similar?

  No, such macros can't exist because if TeX can transmit informations to be
used later by the PostScript interpreter, the opposite is not possible, as you
would like to do here (the VTeX implementation, as far as I know, is the only
one that can do such things, but the source code will obviously not be
portable).

  Nevertheless, some "simple" things like the one you want to do here are easy
to obtain with the standard PSTricks macros. Here is the code, and the idea,
that you can of course adapt (refer to the documentations of the so-called
"Beta" parts):

\documentclass{article}

\usepackage{pst-node}

\pagestyle{empty}

\begin{document}

\SpecialCoor

\psset{subgriddiv=0,griddots=5}

\begin{pspicture}(5,5)\psgrid
  \rput(2,4){\circlenode{A}{A}}
  \rput(4,4){\circlenode{B}{B}}
  \ncline{A}{B}
  \ncput{\pnode{M}}       % M is the middle of (2,4) and (4,4) -> (3,4)
  \ncput{\pnode(0,-2){N}} % N is 2 units below M

  \rput(N){\circlenode{C}{C}}

  \ncline{M}{C}           % Line to a node 2 yunits below the midpoint
\end{pspicture}

\end{document}


  P.S. 1/ I show such examples some time ago (March 2000).
See http://tug.org/pipermail/pstricks/2000/000414.html

       2/ For such needs, more powerful macros would be offered by the
`pst-eucl' package. It is not yet publicly released, but I know that his
author has delivered it to some interested people.
See http://tug.org/pipermail/pstricks/2001/000536.html

D.G.



More information about the PSTricks mailing list