Algorithm for intersecting lines

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Algorithm for intersecting lines

Post by sohel »

How to determine whether two lines intersect, given the end points of the two lines?
Shahab
New poster
Posts: 24
Joined: Sun Nov 10, 2002 2:17 pm

Post by Shahab »

at first, u need an algorithm to determine whether a point is over a line or under it( u can do it using the line equation)

i mean that if u have the line aX+bY+c=0 and also u have the point (x0,y0), if u replace the point in the equation the result of next expression "sign(a*x0+b*y0+c)" shows wheter a point is on the line, over the line or under it. let us know this fuxtion as f(x0,y0). i.e. f(x0,y0)=sign(a*x0+b*y0+c)

so a limited line has intersect with an unlimited line if the two endpoints are not in the same region. it means that if we know that f(x1,y1)*f(x2,y2)<=0 , we also know that the limited line has intersect with the unlimited one.

and when u go to two limited lines, u must do the above procedure 2 times, the first time u must consider the first as an unlimited line and the second line as a limited line, and in the second time, u must do it vice versa, if the the 2 experiments say that they have crossing, u can be sure that they have an intersect, but if it was not like it, u can be sure that they haven't an intersect
Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:

Post by Moni »

Yes! At my computational geometry classes my teacher gave me this topic to solve. That time first I took the help from:

http://mathworld.wolfram.com/Line-LineIntersection.html

And then found a very good help:

http://cm.bell-labs.com/who/clarkson/cis677/lecture/3/

Now I think you will also find it very useful. :)

Good Luck! :wink:
ImageWe are all in a circular way, no advances, only moving and moving!
Partha
New poster
Posts: 5
Joined: Fri Mar 28, 2003 8:51 pm
Location: Bangladesh
Contact:

Post by Partha »

Book name: "Algorithm in C++"
Writer : Robert Sedgewick

See page no. 349. I think this is one of the most efficient algorithm about Line Segment Intersection.

Best of luck.... :lol:
Post Reply

Return to “Algorithms”