How to resolve the algorithm Find the intersection of two lines step by step in the M2000 Interpreter 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 M2000 Interpreter 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 M2000 Interpreter programming language
Source code in the m2000 programming language
Module Lineintersection (lineAtuple, lineBtuple) {
class line {
private:
slop, k
public:
function f(x) {
=x*.slop-.k
}
function intersection(b as line) {
if b.slop==.slop then
=(,)
else
x1=(.k-b.k)/(.slop-b.slop)
=(x1, .f(x1))
end if
}
Class:
module line {
read x1, y1, x2, y2
if x1==x2 then error "wrong input"
if x1>x2 then swap x1,x2 : swap y1, y2
.slop<=(y1-y2)/(x1-x2)
.k<=x1*.slop-y1
}
}
M=line(!lineAtuple)
N=line(!lineBtuple)
Print M.intersection(N)
}
Lineintersection (4,0,6,10), (0,3,10,7) ' print 5 5
You may also check:How to resolve the algorithm Map range step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Loops/Nested step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Variable size/Get step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Inheritance/Single step by step in the Neko programming language