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

Source code in the lambdatalk programming language

{def line_intersect
 {def line_intersect.sub
  {lambda {:111 :121 :112 :122 :211 :221 :212 :222}
   {let { {:x :111} {:y :121} 
          {:z {- {* {- :222 :221} {- :112 :111}}
                 {* {- :212 :211} {- :122 :121}} } }
          {:a {- :112 :111}} {:b {- :122 :121}}
          {:c {- :212 :211}} {:d {- :222 :221}}
          {:e {- :121 :221}} {:f {- :111 :211}}
          {:g {- :121 :211}} {:h {- :122 :121}}
        } {if {> :z 0}
           then {A.new ∞ ∞}
           else {let { {:x :x} {:y :y} {:a :a} {:b :b}
                       {:t1 {/ {- {* :c :e} {* :d :f}} :z} }
                       {:t2 {/ {- {* :a :g} {* :h :f}} :z} }
                } {if {and {>= :t1 0} {<= :t1 1} {>= :t2 0} {<= :t2 1}}
                   then {A.new {+ :x {* :t1 :a}} {+ :y {* :t1 :b}} }
                   else {A.new ∞ ∞}} }}}}}
 {lambda {:1 :2}
  {line_intersect.sub 
   {A.first {A.first :1}} {A.last {A.first :1}}     
   {A.first {A.last  :1}} {A.last {A.last  :1}}     
   {A.first {A.first :2}} {A.last {A.first :2}}     
   {A.first {A.last  :2}} {A.last {A.last  :2}} }}} 
-> line_intersect 

{line_intersect {A.new {A.new 4 0} {A.new 6 10}}
                {A.new {A.new 0 3} {A.new 10 7}}}
-> [5,5]
{line_intersect {A.new {A.new 4 0} {A.new 6 10}}
                {A.new {A.new 0 3} {A.new 10 7.1}}}
-> [5.010893246187364,5.05446623093682]
{line_intersect {A.new {A.new 1 -1} {A.new 4 4}}
                {A.new {A.new 2 5} {A.new 3 -2}}}
-> [2.5,1.5]
{line_intersect {A.new {A.new 0 0} {A.new 0 0}}
                {A.new {A.new 0 3} {A.new 10 7}}}
-> [∞,∞]
{line_intersect {A.new {A.new 0 0} {A.new 1 1}}
                {A.new {A.new 1 2} {A.new 4 5}}}
-> [∞,∞]


  

You may also check:How to resolve the algorithm Hunt the Wumpus step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Fancy programming language
You may also check:How to resolve the algorithm Stack traces step by step in the Slate programming language
You may also check:How to resolve the algorithm Zumkeller numbers step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the 11l programming language