# Collision between two lines

## Recommended Posts

I ahve two lines... how do I tell where they've collided, when they will collide and/or how much they've collided by?

##### Share on other sites
two 3d lines, that is

##### Share on other sites
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.

BTW: if the 2 rays don't intersect, the t return will yield the closest point on the one ray to the other.
[/edit]

##### Share on other sites
How do you derive that equation?

##### Share on other sites
http://www.flipcode.com/geometry/gprimer2_issue02.shtml

(V) Intersection of Two Lines

Should be what you are looking for ;)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628377
• Total Posts
2982326

• 10
• 9
• 14
• 24
• 11