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.)
Question re: Solution | Comment 6 of 20 |
(In reply to Solution by friedlinguini)

When I use
Ax, Ay, Bx, By, Cx, Cy, Dx, Dy equal to
1,3,4,1,3,1,5,3
so that AB is from (1,3) to (4,1) and CD is from (3,1) to (5,3), which intersect,

I get the following values:
By * Cx - Ay * Cx + Ax * Cy - By * Cy + Ay * Bx - Ax * By = 5
By * Dx - Ay * Dx + Ax * Dy - By * Dy + Ay * Bx - Ax * By = 1
Dy * Ax - Cy * Ax + Cx * Ay - Dy * Ay + Cy * Dx - Cx * Dy = -2
Dy * Bx - Cy * Bx + Cx * By - Dy * By + Cy * Dx - Cx * Dy = 4

Then, while 5*1 > 0, (-2)*4 < 0 so the ANDed condition fails. What went wrong here?

  Posted by Charlie on 2003-07-02 03:40:46

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 (3)
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