# detect Ray Crossing? Intersecting?

 0 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¤t=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. more ▼ asked Apr 22 '10 at 08:58 PM Jordan Miller 70 ● 6 ● 6 ● 9 SisterKy 2.4k ● 33 ● 41 ● 59 I thought of another way, but maybe there's a more efficient way. but maybe I could do this: the units firing the raycast can point it slightly down. eventually both rays will hit the terrain mesh and if they cross, that will be reflected in where they hit the ground. once I have where they hit I can triangulate the coordinates and determine the point at which they crossed each other. dude, that's awesome!if you know of an easier way, please let me know, I don't wanna program that all. Apr 22 '10 at 09:14 PM Jordan Miller might want to add the math tag to your question :) Apr 23 '10 at 06:19 AM Random Indie add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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 more ▼ answered Apr 23 '10 at 05:29 AM Random Indie 481 ● 3 ● 8 ● 21 Thanks! this should really help! Apr 23 '10 at 06:06 PM Jordan Miller Hey no problem. :)Like I said if you need any help with the theory feel free to ask. Apr 23 '10 at 06:56 PM Random Indie add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2485
x1525
x210
x151
x25

asked: Apr 22 '10 at 08:58 PM

Seen: 3328 times

Last Updated: Apr 23 '10 at 06:17 PM