Parametric Line Intersection in 2D

Started by
2 comments, last by xissburg 17 years, 10 months ago
If you have two parametric 2D lines equations of the form: r_1(t_1) = p_1 + t_1 d_1 r_2(t_2) = p_2 + t_2 d_2 In 3d you can equate the two equations and eventually simplify to solve for t_1:

      ((p_2 - p_1) X d_2) . (d_1 X d_2)
t_1 = _________________________________
             || d_1 X d_2 ||^2


The problem is that cross product isn't defined in 2D, so what can I do to find for which t the two lines intersect?
Advertisement
The only time I've ever encountered a need for the cross product in 2D was in calculating torque. In that instance I just assumed all the Z's were 0 so the cross product was actually just the z component scalar(the other components multiplied by z to become 0). This might work in your instance as well. Alternativly, you could convert to a non-parametric form of the equations, find the point of collission in the usual way, and then use that point of collission to find the time. In either case, make sure you don't forget the special cases :)
This is a simple case of simultaneous equation solving. Split each equation into its x and y components so you end up with:

r_1x = p_1x + t_1*d_1x
r_1y = p_1y + t_1*d_1y

r_2x = p_2x + t_2*d_2x
r_2y = p_2y + t_2*d_2y

You know at the intersection point that r_1x = r_2x and also that r_1y = r_2y so you end up with:

t_1 = (p_2x - p_1x + t_2*d_2x) / d_1x
t_2 = (p_1y - p_2y + t_1*d_1y) / d_2y

sub one equation into the other and solve, then use the result to solve for the other unknown.
[size="1"] [size="4"]:: SHMUP-DEV ::
more info at softsurfer.com
.

This topic is closed to new replies.

Advertisement