[Programming] How to fix the position of points relatively to others
Denis Girou
Denis.Girou at idris.fr
Mon Mar 27 19:46:20 CEST 2000
-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------
I recently have a question about the way to fix the position of points
relatively to others.
If we know the cartesian coordinates of the points, we can of course make
some computations on them, using the standard TeX macros or some extensions
like `realcalc' or `fp', which allow complex arithmetic opérations. We can
also save the coordinates in some TeX macros and make the computations in
PostScript, using the ! indicator for PostScript special coordinates
(documentation page 72).
But if we do not know the values of the coordinates of the points (when for
instance they are arbitrary nodes), we have nevertheless a powerful way to
manipulate them and to build new points relatively to them, for instance to
put a point at a defined fraction of a segment joining two arbitrary points.
For that, we must define the points as nodes, then to use the \ncput macro
with the "npos" parameter (Beta documentation pages 20-21).
\ncput is a macro primilarly defined to put labels on line connections,
but we can use it too to define new nodes or to execute some arbitrary code.
If the position is not a known fraction of the segment, we can also compute it
using `realcalc' or `fp'.
\documentclass{article}
\usepackage{pst-node}
\pagestyle{empty}
\begin{document}
\SpecialCoor
\psset{subgriddiv=0}
\begin{pspicture}(8,8)\psgrid
\psset{linewidth=0.1,radius=0.5}
\pcline[linestyle=none](1,0)(1,8)
\ncput{\pnode{A}} % Middle of (1,0) and (1,8) -> (1,4)
\pcline[linestyle=none](5,6)(5,8)
\ncput{\pnode{B}} % Middle of (5,6) and (5,8) -> (5,7)
\psline[linecolor=green](A)(B)
%
\Cnode(1,2){G}
\Cnode(6,5){H}
\ncline[linestyle=none]{G}{H}
% Join (0,0), which is the middle of the segment joining G and H, with H
\ncput{\psline(H)}
%
\ncput{\pnode{I}} % I is the middle of the segment joining G and H
\ncput[npos=0.25]{\pnode{J}} % J is the middle of the segment joining G and I
\psline[linecolor=red](I)(J)
%
\psset{linecolor=cyan}
\Cnode(2,7){R}
\Cnode(7,2){S}
\ncline[linestyle=dotted]{R}{S}
\ncput[npos=0.3333]{\pnode{T}} % T is the third of the segment joining R and S
\psline[linecolor=blue](I)(T)
\end{pspicture}
\end{document}
D.G.
-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------
More information about the PSTricks
mailing list