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




define :point [x,y][]
define :line [a, b][
    init: [
        this\slope: div this\b\y-this\a\y this\b\x-this\a\x
        this\yInt: this\a\y - this\slope*this\a\x
    ]
]
 
evalX: function [line, x][
    line\yInt + line\slope * x
]
 
intersect: function [line1, line2][
    x: div line2\yInt-line1\yInt line1\slope-line2\slope
    y: evalX line1 x
 
    to :point @[x y]
]
 
l1: to :line @[to :point [4.0 0.0] to :point [6.0 10.0]]
l2: to :line @[to :point [0.0 3.0] to :point [10.0 7.0]]
 
print intersect l1 l2