Skip to main content
GameDev.net gamedev.net
🔒 Locked

Collision between two lines

Started by Uthman Jul 7, 2004 at 4:45 PM 3 replies 650+ views
Original Post
Uthman
Uthman
I ahve two lines... how do I tell where they've collided, when they will collide and/or how much they've collided by?
"a low level aho master like you couldn't kill me even if I let you"
Uthman
Uthman
two 3d lines, that is
"a low level aho master like you couldn't kill me even if I let you"
Venerable Vampire
Venerable Vampire
Use 3d rays.
For 2 rays defined parametrically as O+t*D = P, where O is the origin, D is a direction, and t is a distance or time along the direction from the origin.
The intersection of the 2 rays is:
t1 = (((o2-o1) x d2) . (d1 x d2)) / (magnitude (d1 x d2))^2
where . is the dot product of 2 vectors, and x is the cross product. ^2 means squared.
Hope this was helpful!

[edit]
BTW: if the 2 rays don't intersect, the t return will yield the closest point on the one ray to the other.
[/edit]
--------------------------------------------------------Life would be so much easier if we could just get the source code.
quant
quant
How do you derive that equation?
-keyboard
choffstein
choffstein
http://www.flipcode.com/geometry/gprimer2_issue02.shtml

(V) Intersection of Two Lines

Should be what you are looking for ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.