Zitat
{-10,-5}->{10,5} = f(x) = 1*x+5
{-10,-20}->{10,20} = g(x) = 2*x
f(x) = g(x)
x+5 = 2x
x = 5
The collision is occuring at x=5. Since this value is within both lines, we assume it's OK.
Therefore, lineal functions written as a*x+b can be solved as:
(b1-b2) / (a2-a1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local function rotatepoint(t)
	return {t[2], -t[1]+0}
end
function lineline(p1,p2,p3,p4)
	local s = { (p2[2]-p1[2])/(p2[1]-p1[1]), (p4[2]-p3[2])/(p4[1]-p3[1]) }
	for i=1,2 do
		if math.abs(s[i]) == math.huge then
			if s[3-i] == 0 then --cross
				return (p1[1] > p3[1]) == (p2[1] < p4[1]) and (p1[2] > p3[2]) == (p2[2] < p4[2])
			else
				return lineline(rotatepoint(p1), rotatepoint(p2), rotatepoint(p3), rotatepoint(p4))
			end
		end
	end
	local oo = {p1[2]-p1[1]*s[1], p3[2]-p3[1]*s[2]}
	col = (oo[2]-oo[1])/(s[1]-s[2])
	return ((col<p1[1]) == (col>p2[1])) and ((col<p3[1]) == (col>p4[1]))
end
It won't work if the slope is NaN (ie, the line's width and height are 0)