# Given a point origin, find ray that intersects two lines

I'm working on a specific shadow calculation for a graphics project. I have a point light source obscured by a straight edge object, and I want to find where the edge of the shadow intersects a certain line.

This can be modeled as shown below, where AB and CD are known segments on the two lines in question, and point L is the known location of a point light source. I need to find the point Q, which is where a ray originating from L intersects the edge containing CD and also intersects the line containing AB.

So A, B, C, D and L are known and I want to find Q. (or R; both are trivial if we know the ray that intersects both lines).

Can this be calculated without using an iterative process? I've drawn it out on paper and can't figure out a system of equations that could be used to solve it.

## 1 Answer

Not going into details but the equation system I think should be that:

• Q is on the AB line
• R is on the CD line
• R is on the QL line

In other view:

• A + q(B-A) = Q
• C + r(D-C) = R
• Q + p(L-Q) = R

If you take them by components that's 9 equation for the 9 unknown: 3 coordinates for R and Q and the 3 helper variables: q, r and p.

After a little bit of messing, r comes to this:

r = (LxCy - LyCx) / (Ly(Dx - Cx) - Lx(Dy - Cy))


Knowing r gives you p and R:

p = (Cx - (Cx - Dy)r) / Lx
R = r(D - C) + C


Then you can get Q as:

Q = (R + pL) / (1 - p)


Keep in mind there are multiple exceptions in the calculation those I did not cover!

• Can you explain how you got the expression for r? I'm trying to calculate it myself because it doesn't make sense to me that p would go to infinity as Lx goes to zero. Jun 30, 2014 at 21:57
• I did find an alternate method of doing this that seems to work. Define a plane by normal and distance from origin. Set it by using Points L, C, and D. Find the intersection of Ray AB with this plane. If that doesn't exist, check Ray BA. I'll write up the description later when I have time. Jul 1, 2014 at 2:57