Line Intersection

Solution
For the two lines given by parametric equations L and M: L = t*A + B M = u*C + D The intersection is in the point: t = (By*Cx - Dy*Cx - Bx*Cy + Dx*Cy) / (Ax*Cy - Ay*Cx) u = (Dy*Ax - By*Ax - Dx*Ay + Bx*Ay) / (Cx*Ay - Cy*Ax) Unless

Ax*Cy - Ay*Cx = 0.

Proof
L = t*A + B M = u*C + D

Intersection:

L = M t*A + B = u*C + D     t = (u*C + D - B) / A

Separated out for x and y:

t = (u*Cx + Dx - Bx) / Ax t = (u*Cy + Dy - By) / Ay

So:

(u*Cx + Dx - Bx) / Ax = t = (u*Cy + Dy - By) / Ay

(u*Cx + Dx - Bx) / Ax = (u*Cy + Dy - By) / Ay        u*Cx + Dx - Bx = (u*Cy + Dy - By) / Ay * Ax  (u*Cx + Dx - Bx) * Ay = (u*Cy + Dy - By) * Ax u*Cx*Ay + Dx*Ay - Bx*Ay = u*Cy*Ax + Dy*Ax - By*Ax u*Cx*Ay - u*Cy*Ax = Dy*Ax - By*Ax - Dx*Ay + Bx*Ay u * (Cx*Ay - Cy*Ax) = Dy*Ax - By*Ax - Dx*Ay + Bx*Ay u = (Dy*Ax - By*Ax - Dx*Ay + Bx*Ay) / (Cx*Ay - Cy*Ax)

If necessary, the equations can be solved for t:

t*A + B = u*C + D     u = (t*A + B - D) / C

u = (t*Ax + Bx - Dx) / Cx u = (t*Ay + By - Dy) / Cy

(t*Ax + Bx - Dx) / Cx = (t*Ay + By - Dy) / Cy (t*Ax + Bx - Dx) * Cy = (t*Ay + By - Dy) * Cx t*Ax*Cy + Bx*Cy - Dx*Cy = t*Ay*Cx + By*Cx - Dy*Cx t*Ax*Cy - t*Ay*Cx = By*Cx - Dy*Cx - Bx*Cy + Dx*Cy t * (Ax*Cy - Ay*Cx) = By*Cx - Dy*Cx - Bx*Cy + Dx*Cy t = By*Cx - Dy*Cx - Bx*Cy + Dx*Cy / (Ax*Cy - Ay*Cx)