I have two rays on a 2D plane that extend to infinity, but both have a starting point. They are both described by a starting point and a vector in the direction of the ray extending to infinity. I want to find out if the two rays intersect, but I don’t need to know where they intersect (it’s part of a collision detection algorithm).
Everything I have looked at so far describes finding the intersection point of two lines or line segments. Is there a fast algorithm to solve this?
Given: two rays a, b with starting points (origin vectors) as, bs, and direction vectors ad, bd.
The two lines intersect if there is an intersection point p:
If this equation system has a solution for u>=0 and v>=0 (the positive direction is what makes them rays), the rays intersect.
For the x/y coordinates of the 2d vectors, this means:
Further steps:
Solving against v:
Inserting and solving against u:
Calculate u, then calculate v, if both are positive the rays intersect, else not.