How to resolve the algorithm Find the intersection of two lines step by step in the Frink 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 Frink 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 Frink programming language

Source code in the frink programming language

lineIntersection[x1, y1, x2, y2, x3, y3, x4, y4] :=
{
   det = (x1 - x2)(y3 - y4) - (y1 - y2)(x3 - x4)
   if det == 0
      return undef

   t1 = (x1 y2 - y1 x2)
   t2 = (x3 y4 - y3 x4)
   px = (t1 (x3 - x4) - t2 (x1 - x2)) / det
   py = (t1 (y3 - y4) - t2 (y1 - y2)) / det
   return [px, py]
}

println[lineIntersection[4, 0, 6, 10, 0, 3, 10, 7]]

  

You may also check:How to resolve the algorithm Palindromic gapful numbers step by step in the J programming language
You may also check:How to resolve the algorithm Reverse words in a string step by step in the Raku programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Draco programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the Klingphix programming language
You may also check:How to resolve the algorithm Chaocipher step by step in the Pascal programming language