# detect Ray Crossing? Intersecting?

I have 2 object that are casting rays, I need a way to know if those rays intersect, and at what point. Here's a birds-eye picture of the situation below. (http://s794.photobucket.com/albums/yy225/JaredShadrak/?action=view&current=raycollisiondetection.jpg)

I thought about creating a vertical plain along one of the rays but I'm not sure if that's the most effective way.

There are a few ways you could do this.

1) You could use the formula found here that gives the intersection point in 3d, however if you're not familiar with linear algebra it might look a little daunting. (even if you are, it's still messy when expanded). Do a find for "In three dimensions, the algebra becomes more complicated." It's about halfway down the page. of course, there's the issue that you're unlikely to have rays actually intersect, and given floating point errors they may never cross according to the computer.

2) You could ignore one component (say Y) and do a 2d line intersection (also available on the first link). Then once you have the point they intersect on the XZ plane, you could just see how far the two rays (at the intersection in XZ) are from one another given a tolerance. However, if the rays are near vertical this could make the floating point errors blow up so it might be a good idea to ignore X or Z if you're 45 degrees above the horizontal, if that's the case, the idea remains pretty much the same.

Your line/plane intersection would definitely work. All you'd have to do is find the point where the ray and plane intersect, then get the perpendicular distance from the ray (forming the vertical plane) to the intersection point on the plane. This should help. This is a more succinct version of the same thing.

Hope that helped, I'm hopped up on cold medication so I can only hope that made some sense. If not, I can try to clarify. No matter what though you're going to probably have to do some algebra (if that's a problem when I'm not so wobbly from the meds I can help out.)

Cheers