Heres another meathod that I came across dont remember where exactly but its quite ingenious
sub segment2segment(x0,y0,x1,y1, x2,y2,x3,y3)
local denom, nume_a, nume_b
denom = ((y3 - y2)*(x1 - x0)) - ((x3 - x2)*(y1 - y0))
nume_a = ((x3 - x2)*(y0 - y2)) - ((y3 - y2)*(x0 - x2))
nume_b = ((x1 - x0)*(y0 - y2)) - ((y1 - y0)*(x0 - x2))
if (denom = 0.0) then // escape to avoid divide by zero
if (nume_a = 0.0) and (nume_b = 0.0) return 0 // paralell
return 0 // co-incident
endif
local ua, ub
ua = nume_a / denom
ub = nume_b / denom
if (ua >= 0.0) and (ua <= 1.0) and (ub >= 0.0) and (ub <= 1.0) then
xi = x0 + ua*(x1 - x0)
yi = y0 + ua*(y1 - y0)
return 1 // intersecting
endif
return 0 // not intersecting
end sub
Edit:
I think it may be the same as above sorry if it is