[1]


Task

Find the point of intersection of two lines in 2D.



The 1st line passes though    (4,0)    and    (6,10) .

The 2nd line passes though    (0,3)    and    (10,7) .




fcn lineIntersect(ax,ay, bx,by,   cx,cy, dx,dy){	// --> (x,y)
   detAB,detCD := det(ax,ay, bx,by), det(cx,cy, dx,dy);
   abDx,cdDx := ax - bx, cx - dx;	// delta x
   abDy,cdDy := ay - by, cy - dy;	// delta y
 
   xnom,ynom := det(detAB,abDx, detCD,cdDx), det(detAB,abDy, detCD,cdDy);
   denom     := det(abDx,abDy, cdDx,cdDy);
   if(denom.closeTo(0.0, 0.0001))
      throw(Exception.MathError("lineIntersect: Parallel lines"));
 
   return(xnom/denom, ynom/denom);
}
fcn det(a,b,c,d){ a*d - b*c }	// determinant