<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Myriad Pro">Dear David,<br>
<br>
here a refinement - only for positive slopes however:<br>
<br>
\documentclass{article}<br>
\usepackage{pstricks,pstricks-add}<br>
\begin{document}<br>
\pagestyle{empty}<br>
\newcommand{\posSlope}[4]{%<br>
\psset{unit=0.5}<br>
\begin{pspicture}(-6,-6)(6,6)<br>
\psgrid[gridcolor=lightgray,gridlabels=0pt,subgriddiv=1](0,0)(-5,-5)(5,5)<br>
\psaxes[labels=none,ticks=none]{-&gt;}(0,0)(-5.5,-5.5)(5.5,5.5)<br>
\Cnode[radius=0.05cm,fillstyle=solid,fillcolor=blue,linecolor=blue](#1,#2){A}<br>
\Cnode[radius=0.05cm,fillstyle=solid,fillcolor=blue,linecolor=blue](#3,#4){B}<br>
\psplot[arrows=&lt;-&gt;,linecolor=blue]%<br>
{#4 #2 sub #3 #1 sub div&nbsp; #2 5 add #1 5 add div ge {5 neg #2 sub #3 #1
sub #4 #2 sub div mul #1 add} {-5} ifelse}%<br>
{#4 #2 sub #3 #1 sub div&nbsp; 5 #4 sub 5 #3 sub div ge {5 #2 sub #3 #1 sub
#4 #2 sub div mul #1 add} {5} ifelse}%<br>
{#4 #2 sub #3 #1 sub div x #1 sub mul #2 add}<br>
\uput[0](5.5,0){$x$}<br>
\uput[90](0,5.5){$y$}<br>
\end{pspicture}<br>
\resetOptions<br>
}<br>
<br>
%Point A must be left of point B (#1 &lt; #3)!!!<br>
%NO VERTICAL LINES possible with that approach.<br>
\posSlope{-4}{-2}{2}{4} \posSlope{-4}{-2}{4}{2}<br>
%First Argument&nbsp;&nbsp;&nbsp;&nbsp; x-Koordinate Point A<br>
%Second Argument&nbsp;&nbsp;&nbsp; y-Koordinate Point A<br>
%Third Argument&nbsp;&nbsp;&nbsp;&nbsp; x-Koordinate Point B<br>
%Fourth Argument&nbsp;&nbsp;&nbsp; y-Koordinate Point B<br>
<br>
\posSlope{-2}{-4}{2}{4} \posSlope{-2}{-4}{4}{2}<br>
<br>
\posSlope{-2}{-2}{2}{2} \posSlope{-2}{4}{4}{4}<br>
\end{document} <br>
<br>
Regards,<br>
<br>
Juergen<br>
</font><br>
Michael Sharpe wrote:
<blockquote cite="mid:DD68EC33-8698-4BAA-84D3-866031AD796B@ucsd.edu"
 type="cite">
  <pre wrap="">On Dec 30, 2008, at 3:09 PM, Herbert Voss wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">Michael Sharpe schrieb:

    </pre>
    <blockquote type="cite">
      <pre wrap="">I think there's a problem here that goes back to the code for
\psIntersectionPoint, which gives a Postscript division by 0  error
where the lines are parallel. This makes your macro fail when the  
line
is either horizontal or vertical. (Try \psSlope(-4,2)(4,2).)
      </pre>
    </blockquote>
    <pre wrap="">Michael,
this is not the problem with my example \psSlope(2,2)(4,1)
it is the negative slope, which needs the nodes sorted in another
order.

Herbert


    </pre>
    <blockquote type="cite">
      <pre wrap="">I think there needs to be a test in the code for the case where the
absolute value of the determinant of dX1 dY1//dX2 dY2 is small-- 
say, &lt;.
01 times the area of ABCD, and in this case, the intersection could  
be
declared to be 100 times the larger of (dX1,dY1), (dX2,dY2) plus the
basepoint. The current code tests only for dX1 or dX2 small, which is
not sufficient to prevent PostScript errors.
      </pre>
    </blockquote>
  </blockquote>
  <pre wrap=""><!---->
Herbert,

The problem happens only when you have too lines that are parallel and  
horizontal.

Try this: I get a PostScript error due to division by 0:

\pnode(1,1){P1}\pnode(3,1){P2}\pnode(1,2){P3}\pnode(4,2){P4}
\psIntersectionPoint(P1)(P2)(P3)(P4){Q}

Now try this modification of your \psIntersectionPoint code, which  
implements what I wrote earlier:

\makeatletter
\def\mypsIntersectionPoint(#1)(#2)(#3)(#4)#5{%
     \pst@getcoor{#1}\pst@tempA
     \pst@getcoor{#2}\pst@tempB
     \pst@getcoor{#3}\pst@tempC
     \pst@getcoor{#4}\pst@tempd
\pnode(!%
      \pst@tempA /YA exch \pst@number\psyunit div def
      /XA exch \pst@number\psxunit div def
      \pst@tempB /YB exch \pst@number\psyunit div def
      /XB exch \pst@number\psxunit div def
      \pst@tempC /YC exch \pst@number\psyunit div def
      /XC exch \pst@number\psxunit div def
      \pst@tempd /YD exch \pst@number\psyunit div def
      /XD exch \pst@number\psxunit div def
     /dY1 YB YA sub def
     /dX1 XB XA sub def
     /dY2 YD YC sub def
     /dX2 XD XC sub def
     /XAC XC XA sub def
     /YAC YC YA sub def
     /det dX1 dY2 mul dX2 dY1 mul sub def % determinant
     /Leng1 dX1 dY1 Pyth def
     /Leng2 dX2 dY2 Pyth def
     Leng1 Leng2 mul .01 mul det abs gt %angle between lines &lt;.01  
radians
     {Leng1 Leng2 lt {100 dY2 mul 100 dX2 mul XC add exch YC add}
     {100 dY1 mul 100 dX1 mul XA add exch YA add} ifelse}
     %else angle between not small
     {XAC dY2 mul YAC dX2 mul sub det div dup dX1 mul XA add exch dY1  
mul YA add }
       ifelse
     ){#5}%
}
\makeatother

\pnode(1,1){P1}\pnode(3,1){P2}\pnode(1,2){P3}\pnode(4,2){P4}
\psIntersectionPoint(P1)(P2)(P3)(P4){Q}

This time, I get no error message---the intersection of these parallel  
line has been declared to be far away on the longer line segment,  
safely out of the picture. Perhaps the 100 should be 1000, and .01  
radians should be .001 radians.)

Michael
_______________________________________________
PSTricks mailing list
<a class="moz-txt-link-abbreviated" href="mailto:PSTricks@tug.org">PSTricks@tug.org</a>
<a class="moz-txt-link-freetext" href="http://tug.org/mailman/listinfo/pstricks">http://tug.org/mailman/listinfo/pstricks</a>


  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="65">-- 
 J&uuml;rgen Gilg
 Austr. 59
 70376 Stuttgart
-------------------------------------
 Tel       0711.59 27 88
 e-Mail    <a class="moz-txt-link-abbreviated" href="mailto:gilg@acrotex.net">gilg@acrotex.net</a>
 Websites  <a class="moz-txt-link-abbreviated" href="http://www.acrotex.net">www.acrotex.net</a>
           <a class="moz-txt-link-abbreviated" href="http://www.brueckenkurs-physik.de">www.brueckenkurs-physik.de</a>
           <a class="moz-txt-link-abbreviated" href="http://www.gilligan-online.de">www.gilligan-online.de</a>
</pre>
</body>
</html>