Let's see if I can clarify the maths a bit.
You have two lines:
- Line
r1such that some pointp1 = a + L*bwhereais a position vector andbis the direction andLis a parameter. - Line
r2such that some pointp2 = c + M*dwherecis a position vector anddis the direction andMis a parameter.
Each line has its own parameter.
You want to find where these intersect. At the intersection point, p1 = p2. Unless r1 and r2 are parallel, there must exist some values for L and M for which p1 = p2 is true. You only need one of these values to find the intersection point.
This is easiest to solve by splitting r1 and r2 from cartesian form into parametric form, where the x and y coordinates of the vectors are described separately:
r1 is such that p1x = ax + L*bx and p1y = ay + L*by.
r2 is such that p2x = cx + M*dx and p2y = cy + M*dy.
You can then rearrange the equations to isolate and eliminate either L or M and solve for the other. The resultant equation (derivation herederivation here) is, M = ((cy - ay) * bx - (cx - ax) * by) / (dx * by - dy * bx). You could write your code around that. This tutorial might also help to understand the concepts.