       subroutine llintr(p1,p2,q1,q2,i,xi,yi)
	  
c***********************************************************************
c      Line/Line INTersection
c      Written by Orlando Camargo Rodriguez
c      orodrig@ualg.pt
c      Universidade do Algarve
c      Physics Department
c      Signal Processing Laboratory
c      Faro, 28/11/2010 at 19:30
c      Reference: Wikipedia
c****&******************************************************************

       integer*4 i

       real*8 p1(2),p2(2),q1(2),q2(2)
       real*8 x1,x2,x3,x4,xi
       real*8 y1,y2,y3,y4,yi
       real*8 d
       
c***********************************************************************

       i = 0
       
       x1 = p1(1)
       y1 = p1(2)
       x2 = p2(1)
       y2 = p2(2)
       x3 = q1(1)
       y3 = q1(2)
       x4 = q2(1)
       y4 = q2(2)
       
       d = (x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)
       
       if (abs(d).gt.1e-16) then
          
	  i = 1

          xi = ( (x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4) )/d
	  yi = ( (x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4) )/d
	  
       end if

c***********************************************************************
c      Back to main:
c***********************************************************************
       
       return
       
       end
