[pstricks] Automate a line drawing routine

Juergen Gilg gilg at acrotex.net
Tue Dec 30 08:04:25 CET 2008


Dear David,
> Here's a really clumsy solution that uses only TeX and pstricks--- 
> doubtless it would have been better to craft one in PostScript.
>
> Michael
>   
here another approach with some cases. Seems to work for all lines 
except VERTICAL ones.

\documentclass{article}
\usepackage{pstricks,pstricks-add}
\begin{document}
\pagestyle{empty}
\newcommand{\DaveArnold}[4]{%
\psset{unit=0.5}
\begin{pspicture}(-6,-6)(6,6)
\psgrid[gridcolor=lightgray,gridlabels=0pt,subgriddiv=1](0,0)(-5,-5)(5,5)
\psaxes[labels=none,ticks=none]{->}(0,0)(-5.5,-5.5)(5.5,5.5)
\Cnode[radius=0.05cm,fillstyle=solid,fillcolor=blue,linecolor=blue](#1,#2){A}
\Cnode[radius=0.05cm,fillstyle=solid,fillcolor=blue,linecolor=blue](#3,#4){B}
\psplot[arrows=<->,linecolor=blue]%
{#4 #2 sub #3 #1 sub div abs 1 ge  {5 neg #2 sub #3 #1 sub #4 #2 sub div 
mul #1 add} {-5} ifelse}%
{#4 #2 sub #3 #1 sub div abs 1 ge{5 #2 sub #3 #1 sub #4 #2 sub div mul 
#1 add} {5} ifelse}%
{#4 #2 sub #3 #1 sub div x #1 sub mul #2 add}
\uput[0](5.5,0){$x$}
\uput[90](0,5.5){$y$}
\end{pspicture}
\resetOptions
}
%NO VERTICAL LINES possible with that approach.
\DaveArnold{-4}{-2}{-3}{4} \DaveArnold{-4.5}{-2.5}{3}{-2.5}
%First Argument     x-Koordinate Point A
%Second Argument    y-Koordinate Point A
%Third Argument     x-Koordinate Point B
%Fourth Argument    y-Koordinate Point B

\DaveArnold{-1}{-2}{3}{3} \DaveArnold{-4}{-4}{1}{2}

\DaveArnold{0}{0}{2}{1} \DaveArnold{-4}{4}{1}{-2}
\end{document}

Regards,

Jürgen


-- 
 Jürgen Gilg
 Austr. 59
 70376 Stuttgart
-------------------------------------
 Tel       0711.59 27 88
 e-Mail    gilg at acrotex.net
 Websites  www.acrotex.net
           www.brueckenkurs-physik.de
           www.gilligan-online.de



More information about the PSTricks mailing list