Looks like an assignment problem to me. Here is the logic that will help you write the code.
Let us call the first Ray as R0
.
Locus of a point on R0
is defined as P
:
P = P0 + alpha x V0
For the second ray R1
:
P = P1 + beta x V1
Since they should intersect:
P0 + alpha x V0 = P1 + beta x V1
alpha
and beta
are unknowns and we have two equations in x
any y
.
Solve for the unknowns and get back the point of intersection.
i.e.,
P0.x + alpha * V0.x = P1.x + beta * V1.x
P0.y + alpha * V0.y = P1.y + beta * V1.y
solve for alpha
and beta
.
If there is a real positive solution for both alpha
and beta
, rays intersect.
If there is a real but at least one negative solution for both alpha
and beta
, extended rays intersect.