- Home /
Point of intersection between two rays
Hey guys! I'm just a bit confused on how to find the point of intersection between two rays, I've found a bit of information of two line segments, but I'd rather it be optimised towards two rays, Is there any information you guys could offer? Thanks in advanced!
Edit: Sorry, forgot to mention, I need this for 2D.
Answer by robertbu · Jul 30, 2014 at 04:00 AM
The Unity Wiki has a Math3D script. In it you will find a LineLineIntersection() function and a ClosestPointOnTwoLines() function. They define their lines in ray form (point and direction), but the tests use lines (not line segments or ray). To restrict them to a ray, just determine if the point(s) found are before or after the ray origin based on the direction of the ray.
Oh hey, Sorry I didn't make this super clear, I need this for 2D, I'm sure this will work but it feels a bit over-the-top. Thanks!
2D math and 3D math are the same, just drop out the third dimension.
Answer by Kiwasi · Jul 30, 2014 at 04:33 AM
Steps are
Determine the equation for each line
Set the lines to equivalent to determine the point they cross
Determine if the point is within the bounds of the ray
Your answer
