Jump to content
  • Advertisement
Sign in to follow this  
Jnz86

Ray vs Ray (2D)

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i feel so stupid, but here it goes: lets say Ray has these components: Vector2 Origin; Vector2 Direction;(normalized) then, any point on ray P = Origin + Direction*t; when i want to find where two ray's intersect, i do this: P1 = P2; Origin1 + Direction1*t1 = Origin2 + Direction2*t2; and now i am lost, i got two unknown variables(t1,t2) and only one equation... how to find t1,t2 ?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Ah... but you have two equations:

origin1.x + t1 * direction1.x = origin2.x + t2 * direction2.x
origin1.y + t1 * direction1.y = origin2.y + t2 * direction2.y

Share this post


Link to post
Share on other sites
Assuming that t is time then you need a speed.

Origin+(Speeed*Direction)*Time;

Other wise you are always going at 1 unit per time unit.

For the two rays time will be the same.

So it is

Origin1+(Speed1*Direction1)*TIME=Origin2+(Speed2*Direction2)*TIME

And now you are solving for one unknown... Time...

Hope that helps.
------------------------------------------------------------------

Share this post


Link to post
Share on other sites
Quote:

Assuming that t is time then you need a speed.

Origin+(Speeed*Direction)*Time;

Other wise you are always going at 1 unit per time unit.

For the two rays time will be the same.

So it is

Origin1+(Speed1*Direction1)*TIME=Origin2+(Speed2*Direction2)*TIME

And now you are solving for one unknown... Time...

Hope that helps.
------------------------------------------------------------------

If i understand correctly, this is more for particle collision, i don't want this, i want the WHOLE lines to collide, not just point
(it's hard to say, but it's not what i need)


Quote:

Ah... but you have two equations:

origin1.x + t1 * direction1.x = origin2.x + t2 * direction2.x
origin1.y + t1 * direction1.y = origin2.y + t2 * direction2.y

Yes, but from those 2 equations i derived this one:
t2 = ((O2.y - O1.y)/D1.y - (O2.x + O1.x)/D1.x)/(D2.x/D1.x - D2.y/D1.y)
and what if D1.y is 0? or D1.x is 0? It won't work, there must be a simpler way to find collision between rays;

I am thinking about converting one ray to plane, and then test collision between ray and plane...
Well, anyway, now i am going out and will be back only tomorrow, so, if you have any ideas, share...

Share this post


Link to post
Share on other sites
Using a planar equation you get (origin1+t*direction1).normal = origin2.normal
Which in this case normal = <direction2.y,-direction2.x>
So, dotting with the normal can be replaced with the scalar 2d cross product with direction2
So, (origin1+t*direction1) x direction2 = origin2 x direction2
Solving for t, t = (o2 x d2 - o1 x d2)/(d1 x d2)
If d1 x d2 = 0 then they are parallel and there is no intersection
Unless (o2 x d2 - o1 x d2) also = 0, then they are the same line

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!