Line Interception
hi all,
I wanted to post this because
I need it for my new game and can''t find it anywhere:
how dows one find out if two lines intercect?
if they do, at which point?
and in case more than one line intercepts our primary
line, which of the intercepting lines does so first?
thanks all,
Hugo Ferreira
UniteK Future
Dude, that''s high school geometry! I don''t think you looked very far. Anyways...
Using the slope-intercept equation of a line,
y = mx + b
where b is a constant (the value of y when x is zero, or the vertical intercept of the line). If you''re lines are defined in point pairs {(x1,x2), (y1,y2)}, then
y2 - y1 = m(x2 - x1) + b ...(1)
Calculate m for each of your lines and compare. If m1 == m2, then the lines are parallel and never intersect. For all other outcomes the lines intersect somewhere.
if the lines intersect, then we can choose an arbitrary point (x,y) as the point of intersection and define the lines as {(x1,y1),(x,y)} and {(x2,y2),(x,y)}. From (1) we see that
y = m1(x - x1) - y1 ...(2)
We then substitute that into the other line''s equation (for y) to obtain
m1(x - x1) - y1 - y2 = m2(x - x2)
Rearranging terms
x = (y2 + y1 + m2x2 - m1x1)/(m2 - m1)
All the terms on the right hand are known, so you get a numeric value for x. Plug that into (2) and you''ve got y.
Using the slope-intercept equation of a line,
y = mx + b
where b is a constant (the value of y when x is zero, or the vertical intercept of the line). If you''re lines are defined in point pairs {(x1,x2), (y1,y2)}, then
y2 - y1 = m(x2 - x1) + b ...(1)
Calculate m for each of your lines and compare. If m1 == m2, then the lines are parallel and never intersect. For all other outcomes the lines intersect somewhere.
if the lines intersect, then we can choose an arbitrary point (x,y) as the point of intersection and define the lines as {(x1,y1),(x,y)} and {(x2,y2),(x,y)}. From (1) we see that
y = m1(x - x1) - y1 ...(2)
We then substitute that into the other line''s equation (for y) to obtain
m1(x - x1) - y1 - y2 = m2(x - x2)
Rearranging terms
x = (y2 + y1 + m2x2 - m1x1)/(m2 - m1)
All the terms on the right hand are known, so you get a numeric value for x. Plug that into (2) and you''ve got y.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement