Given a point origin, find ray that intersects two lines

214 Views Asked by At

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.

enter image description here

1

There are 1 best solutions below

2
On

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!