Archived

This topic is now archived and is closed to further replies.

Boris Karloff

Collision detection on parallel lines?

Recommended Posts

I''m trying to detect when two objects travelling in certain directions along two line segments which are both part of the same infinite line collide. I already managed to find out if, and where, these two line segments overlap, but now I need to figure where, exactly, these objects collide. I have the start and endpoints for both segments, the speeds of both objects, and the two points where the line segments start and end, overlapping. (for instance, the start of segment two and the end of segment one.) Normal collision detection, taking the intersect point of both paths and figuring out when both objects get there, isn''t a problem, but since this one has an infinite number of intersect points between overlap point one and two, I have no idea how to go about this.... Haven''t found any helpful collision detection tutorials dealing with parallel paths either. Any help?

Share this post


Link to post
Share on other sites
You have a one dimensional space(a line), two positions, and two velocities.
P1+V1*t=P2+V2*t
where P1 is the position of object #1 and V1 is the velocity of object #1. The same for P2 and V2. T is the elapsed time.

P1-P2=t * (V2-V1)

(P1-P2)/(V2-V1)=t

Then, to get where exactly they collide, just calculate the the position for either object at time t (which would be either P1+V1*t or P2+V2*t)

I think

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
You have a one dimensional space(a line), two positions, and two velocities.
P1+V1*t=P2+V2*t
where P1 is the position of object #1 and V1 is the velocity of object #1. The same for P2 and V2. T is the elapsed time.

P1-P2=t * (V2-V1)

(P1-P2)/(V2-V1)=t

Then, to get where exactly they collide, just calculate the the position for either object at time t (which would be either P1+V1*t or P2+V2*t)

I think



Hmm... Sounds like you''re on to something there... I only have one problem.. In order to find their position, I need time t, right?

But how do I know at what time they will collide? What do I need to do to figure out what t will be?

Share this post


Link to post
Share on other sites
t is the time they collide. You get t from the last formula I did:
(P1-P2)/(V2-V1)=t

P is the initial position of the object, not the position when they collide. To get the position where the objects collide, you find t and then calculate P1+V1*t or P2+V2*t

Share this post


Link to post
Share on other sites
Ah, of course, I see now.

Thanks! That works like a charm. I managed to figure out the P1+V1*t=P2+V2*t part, but solving equations is something I really suck at...
Only problem I have now is that the collission might occur twice: If one of the objects overtakes another object (or if they start at the same point), and then stops earlier than the second object, the second object will pass the first objects, which would be the second time they collide. That''s a simple condition to check for though, so it should work fine.

Anyway, thanks again!

Share this post


Link to post
Share on other sites