When I tried it with different lines, it came out to -0,-0 every time. The line should have intersected at -300,-250.
Code: Select all
function intersect(x1,y1,x2,y2,x3,y3,x4,y4)
-- d = r_1*t + r_2*t
-- d = (r_1+r_2)t
-- d/t = r_1+r_2
-- t = d/(r_1+r_2)
print("Line 1:",x1,y1,x2,y2)
print("Line 2:",x3,y3,x4,y4)
local d=magnitude(x4-x1,y4-y1)
print("Dist:",d)
local r1,r2=math.abs((y2-y1)/(x2-x1)),math.abs((y4-y3)/(x4-x3))
print("Slopes:",r1,r2)
local r=r1+r2
print("Slope:",r)
local y=d/r
local x=r1*y
print(x,y)
return x,y
end