Jump to content

Need help finding if two line segments intersect or not.

Go to solution Solved by MrBucket101,

@Revan117

http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

This seems like a good start.

 

One thing to consider, is it an intersection if one segment touches the other, but does not overlap?

 

For my java class I was given an assignment to code two line segments and test if they intersect or not. I'm not asking for the code, I'm trying to do that myself, I'm just wanting to figure out the formula for the two line segments. I have read to use cross product or dot product, but I still need help with the math, plz help.

Link to post
Share on other sites

Check to see if the two lines have the same slope, if not then they intersect.

 

Edit: Missed the part where it said line segment, there is a bit more math involved

 

Yeah, that's what I saw, it's not as easy as getting the slope line to get the line segment. I need more help on that part

Link to post
Share on other sites

What input are you meant to be giving the program

Intersection 1              no intersection 1

                       

7 8                               5 10

5 12                             5  2

10 10                           2  1     

3 10                             8  7

Link to post
Share on other sites

@Revan117

http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

This seems like a good start.

 

One thing to consider, is it an intersection if one segment touches the other, but does not overlap?

 

Link to post
Share on other sites

@Revan117

http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

This seems like a good start.

 

One thing to consider, is it an intersection if one segment touches the other, but does not overlap?

 

Thx I will starting reading it, yes i believe that it's still an intersection.

Link to post
Share on other sites

i go for the method that is pretty much like the one described at the beginning of this tutorial: http://ncase.me/sight-and-light/

i don't think that the explaination there is very good though, feel free to ask specific questions

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×