hi,
i need to find the intersection point of 2 line segments (lines are finite, i.e., they have end points).
e.g. segment 1 from x1,y1 to x2,y2 -- segment 2 from x3,y3 to x4,y4
you can assume m1 and m2 are the gradients of segment 1 and segment 2 respectively
similarly, c1 and c2 being the y-intercepts of segment 1 and segment 2 respectively
using 'y=mx+c' i can easily find the equations of both lines and then derive the intersection point from those equations and check if that point actually lies on both line segments (intersection point may not be between the end points).
my problem is when i calculate the gradients (m1 and m2) i do [y2-y1]/[x2-x1] there for if one of the lines is vertical then im gonna have problems. how can i deal with this?
another problem is that if the two segments intersect at a point which is also the same as one of the end points then i want to assume that they are not intersecting..
e.g. if segment 1 is from 2,3 to 3,7 and segment 2 is from 3,7 to 7,3 then i want to assume they dont intersect
2 replies to this topic
#1
Posted 09 March 2011 - 09:48 AM
|
|
|
#2
Posted 09 March 2011 - 02:14 PM
The more general equation of a line is Ax+By = C, you can handle vertical lines with that version.
#3
Posted 10 March 2011 - 05:20 PM
I haven't quite worked it out fully but....
[y2-y1]/[x2-x1] and the point slope form of a linear equation y-y1=m(x-x1) you can find the slope-intercept form y=mx+b.
Your special case is the vertical line.
If x1==x2, then y=x1 or y=x2.
Otherwise, use point slope form to form your y=mx+b.
Set your equations equal to each other to find the intersections.
If none of the lines are vertical, you should acquire x. Plug x back into one of the equations you had set equal to each other to acquire y.
If (x,y) falls between your x1,x2 and x3,x4 and also y1,y2 and y3,y4 then you have an intersection within the given boundary.
If you have a vertical line then you already have acquired x. Example: point1 (3,1) and point2( 3,4); x = 3;
Plug this into one of your other equations and solve for y.
Check to see if your (x,y) fall between your points.
For the next problem, do the same as above.
Once you've found the intersection point, just check to see if it equals one of your given points.
That's how I would go about it...
[y2-y1]/[x2-x1] and the point slope form of a linear equation y-y1=m(x-x1) you can find the slope-intercept form y=mx+b.
Your special case is the vertical line.
If x1==x2, then y=x1 or y=x2.
Otherwise, use point slope form to form your y=mx+b.
Set your equations equal to each other to find the intersections.
If none of the lines are vertical, you should acquire x. Plug x back into one of the equations you had set equal to each other to acquire y.
If (x,y) falls between your x1,x2 and x3,x4 and also y1,y2 and y3,y4 then you have an intersection within the given boundary.
If you have a vertical line then you already have acquired x. Example: point1 (3,1) and point2( 3,4); x = 3;
Plug this into one of your other equations and solve for y.
Check to see if your (x,y) fall between your points.
For the next problem, do the same as above.
Once you've found the intersection point, just check to see if it equals one of your given points.
That's how I would go about it...
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









