How to resolve the algorithm Find the intersection of two lines step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Find the intersection of two lines step by step in the zkl programming language

Table of Contents

Problem Statement

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) .

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Find the intersection of two lines step by step in the zkl programming language

Source code in the zkl programming language

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

lineIntersect(4.0,0.0, 6.0,10.0,  0.0,3.0, 10.0,7.0).println();

  

You may also check:How to resolve the algorithm Hash from two arrays step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm String concatenation step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Modular arithmetic step by step in the Owl Lisp programming language
You may also check:How to resolve the algorithm Comments step by step in the Arendelle programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Common Lisp programming language