Computer Science Canada Intersections of two lines |
Author: | Windsurfer [ Wed Aug 30, 2006 10:59 pm ] | ||
Post subject: | Intersections of two lines | ||
Okay, a while back i had been messing with this line intersect function... It is supposed to return true if two lines are intersecting. For some reason, it gives false positives, but no false negatives. Any help by anyone? I can't get a concrete example of when it gives the false positive, as it relies on real numbers and happens infrequently... but it has quite an impact when checking multiple lines.
Hopefully it isn't too complicated.... I made it so that it uses y = mx + b format, with extra stuff to correct it when m = infinity and so on. |
Author: | BenLi [ Thu Aug 31, 2006 1:24 pm ] |
Post subject: | |
well without reading your code, you said Quote: It is supposed to return true if two lines are intersecting Any two lines will intersect if it's not parallel. Why don't you check that instead? |
Author: | Bored [ Thu Aug 31, 2006 2:29 pm ] |
Post subject: | |
When he says lines he is talking about line segments. Therfore even though the extended line will touch it does not mean that the line segments are touching. So instead he needs to find the point of intersection and see if its within both line segments or atleast thats what I think he's doing. |
Author: | Bored [ Thu Aug 31, 2006 2:53 pm ] | ||
Post subject: | |||
I added this code to the bottom to generate random lines and test your program:
And after extensive trials I have not seen one wrong case. Try it for yourself. If you find one that is wrong take a picture and post it as it seems to work fine for me. Maybe your just implimenting it into another program wrong or something like that. |
Author: | Windsurfer [ Thu Aug 31, 2006 3:43 pm ] | ||
Post subject: | |||
Well, if you've ever played my game Forces you may have noticed what i call "offscreen bubbles". What i'm actually doing is finding the intersection of a line drawn from the center of the screen to where the enemy is. Where it intersects the border, i put a bubble. You may have noticed it flickering... But that's just one example. But here is that same problem written as a program. Try moving your mouse around the outside, and watch the line flicker.
|
Author: | zylum [ Fri Sep 01, 2006 12:01 am ] | ||
Post subject: | |||
i dont see any flicker either. here's a simple function thats a little easier to read:
|
Author: | Windsurfer [ Sun Sep 03, 2006 10:53 am ] | ||
Post subject: | |||
Okay, your function does work, and IS easier to read, but it doesn't work for line segments. It also doesn't work if one of the lines is vertical... which is kind of critical. It also doesn't work if a line is a point, and it ALSO doesn't always return the right boolean. Take a look.... move your mouse off the right of the screen:
|
Author: | zylum [ Mon Sep 04, 2006 12:54 am ] | ||
Post subject: | |||
k, this one should work a little better:
|
Author: | Windsurfer [ Mon Sep 04, 2006 7:21 am ] |
Post subject: | |
Wow. This works perfectly. Thanks... all I know is that your function works, and does resemble mine... sort of. Anyhoo, this is awsome. Maybe now i can start putting walls in Forces. + bits ![]() |