Share for you function to calculate two line segments intersection.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | function intersection(p11,p12,p21,p22) local Z = (p12.y-p11.y)*(p21.x-p22.x)-(p21.y-p22.y)*(p12.x-p11.x); local Ca = (p12.y-p11.y)*(p21.x-p11.x)-(p21.y-p11.y)*(p12.x-p11.x); local Cb = (p21.y-p11.y)*(p21.x-p22.x)-(p21.y-p22.y)*(p21.x-p11.x); if Z == 0 and Ca == 0 and Cb == 0 then return nil end if Z == 0 then return nil end local Ua = Ca/Z; local Ub = Cb/Z; local pt = {} pt.x = p11.x + (p12.x - p11.x) * Ub; pt.y = p11.y + (p12.y - p11.y) * Ub; if 0 <= Ua and Ua <= 1 and 0 <= Ub and Ub <= 1 then -- ( (Ua == 0)||(Ua == 1)||(Ub == 0)||(Ub == 1) ) ? -- result.type = ctOnBounds : -- result.type = ctInBounds; else return nil end return pt end |
Improve your google rank today check this out! http://goo.gl/YzNKa
Thanks