[pstricks] Automate a line drawing routine

David Arnold dwarnold45 at suddenlink.net
Tue Dec 30 20:41:33 CET 2008


Herbert, Jurgen, Michael, et al,

Thanks for the wonderful tips. I am learning a lot.

I'd like to combine what I've learned in these examples with this one  
provided by Herbert. I'd like to:

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

With what Herbert provides here, but his code assumes that the line  
will enter and leave on the top and bottom boundaries. May I make one  
more request, as it would help me learn a great deal.

Can Herbert's code be adapted with an if...else something or other to  
accommodate for the fact that the line might exit on the right or the  
top boundary and might enter on the left or bottom entry? I can make  
sure that the first point lies to the left and under the second point  
in \DaveArnold, ensuring positive slope.

Thanks. This would help a great deal if possible.

David.

On Dec 30, 2008, at 12:27 AM, Herbert Voss wrote:

> David Arnold schrieb:
>
>> I'd like to produce some line graphs, such as:
>>
>> http://www.kutasoftware.com/FreeWorksheets/Slope%20From%20a% 
>> 20Graph.pdf
>>
>> Now, I can produce these one at a time, not much problem, but I'd
>> like to automate the task a bit:
>>
>> 1. I like the domain to be [-5,5], and the range [-5,5]. I'd like the
>> x-axis labeled -5 and 5 at each end, same for the y-axis. I'd like
>> the x- and y-axes labeled at the right and top ends with "x" and "y",
>> respectively.
>>
>> 2. The user can easily choose two points P and Q on the grid.
>>
>> 3. The code automatically determines the equation of the line through
>> P and Q (no horizontal or vertical allowed) and then clips it to the
>> domain and range in item #1. The line should be drawn with arrowheads
>> at each end of the line.
>
>
> \documentclass[dvips]{article}
> \usepackage{pstricks-add}
> \begin{document}
>
> \psset{arrows=<->,dotscale=1.5,arrowscale=2,unit=.5cm}
> \begin{pspicture}(-5.5,-5.5)(6,6)
> \def\labelFontSize{\scriptscripstyle}
> \psgrid[gridcolor=lightgray,gridlabels=0pt,
>   subgriddiv=1](0,0)(-5,-5)(5,5)
> \psaxes[Dx=5,Dy=5,showorigin=false](0,0)(-5.5,-5.5)(5.5,5.5)[$x$,0] 
> [$y$,90]
> \psIntersectionPoint(-1,-3)(2,4)(-5,5)(5,5){P0}
> \psdot[linecolor=blue](-1,-3)
> \psIntersectionPoint(-1,-3)(2,4)(-5,-5)(5,-5){P1}
> \psdot[linecolor=blue](2,4)
> \psline(P0)(P1)
> \end{pspicture}
>
> \end{document}
>
>
> Herbert
> _______________________________________________
> PSTricks mailing list
> PSTricks at tug.org
> http://tug.org/mailman/listinfo/pstricks



More information about the PSTricks mailing list