All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Intersecting lines (Posted on 2003-07-01) Difficulty: 3 of 5
You are given two straight line segments, each defined by the coordinates of its endpoints. Segment AB goes from (Ax,Ay) to (Bx,By) and segment CD - from (Cx,Cy) to (Dx,Dy).

How would you determine if the two line segments intersect?

(Assume that you can't just draw the lines and see)

See The Solution Submitted by levik    
Rating: 4.0000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
re: No Code, just theory | Comment 12 of 20 |
(In reply to No Code, just theory by nikki)

Indeed descriptions in English are just as valid as descriptions in computer language.

However I find a problem with
"Using the points given, find the Slope of each line - call them mAB and mCD. You'd need a check to see if |mAB| = |mCD| but that's a trivial case."

I don't see the use of the absolute value indications. If one has slope 2 and the other has slope -2, it's the ordinary case of seeing where they intersect.

Also even if the slopes are themselves the same, the lines could be either parallel or the same line. If parallel they don't intersect. If they are the same line, you have to check if the endpoint of either is located between the two endpoints of the other. If so, there's an extended intersection (in the set theory definition of intersection, as they share not only 1 but many points).

Likewise your solution considers one of the lines' being vertical, but there is the possibility that both are vertical, with the same considerations as other lines with the same slope.

Your solution, with the addition of the above, are basically what the code in Algebraic Solution did. And specifying it in English is fine.

  Posted by Charlie on 2003-07-03 03:15:44

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (8)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information