[pstricks] Automate a line drawing routine

Michael Sharpe msharpe at ucsd.edu
Mon Dec 29 23:48:46 CET 2008

On Dec 29, 2008, at 12:27 PM, David Arnold wrote:

> Jurgen et al,
> I would not pick points P and Q that lie on the boundary. So I would  
> want the arrows at the end of the lines where the lines exit on a  
> boundary of the grid.

Here's a really clumsy solution that uses only TeX and pstricks--- 
doubtless it would have been better to craft one in PostScript.


\newdimen\islope%inverse slope
\def\getends(#1,#2)(#3,#4){%P=(#1,#2), Q=(#3,#4)
\cntc=#3\advance\cntc by -#1
\cntd=#4\advance\cntd by -#2
\divide\dimd by \cntc %slope now in \dimd
\divide\dimc by \cntd %inverse slope now in dimc
%compute intersection with x=5: y0+slope*(5-x0)
\cntA=5\advance\cntA by -#1 %(5-x0)
\dime=\dimb\advance\dime by \the\cntA\slope%y0+slope*(5-x0)
\ifdim\dime<\dimg %
   \ifdim\dime>\dimh %
     \pnode(5,\dime){P\the\cntB}\advance\cntB by 1 %
%compute intersection with x=-5: y0-slope*(5+x0)
\cntA=5\advance\cntA by #1 %(5+x0)
\dime=\dimb\advance\dime by -\the\cntA\slope%y0-slope*(5+x0)
\ifdim\dime<\dimg %
     \pnode(-5,\dime){P\the\cntB}\advance\cntB by 1 %
%compute intersection with y=5: x0+islope*(5-y0)
\cntA=5\advance\cntA by -#2 %(5-y0)
\dime=\dima\advance\dime by \the\cntA\islope%x0+islope*(5-y0)
\ifdim\dime<\dimg %
   \ifdim\dime>\dimh %
     \pnode(\dime,5){P\the\cntB}\advance\cntB by 1 %
%compute intersection with y=-5: x0-islope*(5+y0)
\cntA=5\advance\cntA by #2 %(5-y0)
\dime=\dima\advance\dime by -\the\cntA\islope%x0-islope*(5+y0)
\ifdim\dime<\dimg %
   \ifdim\dime>\dimh %
     \pnode(\dime,-5){P\the\cntB}\advance\cntB by 1 %

More information about the PSTricks mailing list