Line Intersection

by Crazy Star

Posted on December 28, 2005 at 7:57 AM

This has several bugs bug I got fed up with it so I decided to just upload :s
If anyone figures out any bugs then don't hesitate to let me know. Examples of bug causes:
-Negative numbers
-checking endpoints of lines

For those not registered, you can just delete the 2nd object and it should work...

LINE INTERSECTION<small>(x1,y1,x2,y2,x3,y3,x4,y4)</small>

Find out where two lines intersect each other pretty much like you'd do it in math class.

Works with vertical lines.
Works with vertical and horizontal line.
Works with point and any line.
Works with 2 points.
Parallel lines gives 2 intersection points if they overlap.


ludamad commented December 30, 2005 at 2:56 AM
cool beans
firestormx commented December 30, 2005 at 6:54 AM
Awesome stuff. =)
mooselumph commented December 30, 2005 at 7:46 AM
Wow, that's pretty awesome. It uses the y=mx+b form, right? I'm not sure how it works, but I saw a calculation that looked like slope.
Crazy Star commented December 30, 2005 at 8:30 AM
*realizes this doesn't have a lot of comments* whoops

"It uses the y=mx+b form, right?"
yup only I called m a so it's y=ax+b

This is actually just an old gmd/gm6 I dug up improved and turned into an example. SO... how I ever got intersectx=abs(b2-b1)/abs(a2-a1) I don't know but it was probably just by messing around with an expression that had x in it.... :)

This is what it does:
-receive two sets of points that forms two lines
-figure out a and b (or m and b)
b1=y1-a1*x1; //remember y increaces downwards
-check if one's vertical and if so do everything opposite
-handle other special cases like those described in the description...

I should probably make another version without the bugs and (slightly) optimized when I'm done being mad at this example for not doing as I want it to :)
Crazy Star commented January 11, 2006 at 10:32 PM
<b>New version out! (1.1)</b>

Fixed all known bugs:
-negative numbers does not reverse
-endpoints are always valid

I also got rid of the parallel lines and points feature because I thought it useless and that it only slowed things down. If anyone misses it it's still in the old file....
I changed other minor stuff as well.

So is it bugfree know? I dunno I guess it isn't. I wouldn't trust it to be used in one of my games yet so I'll probably update again :s

Oh... and in my previous comment I didn't mean that there wasn't a lot of user comments I meant code comments. Thanks for your feedback all!

<a href="">Here's the file</a>
<a href="">And here's a screenshot</a>
Crazy Star commented January 11, 2006 at 10:35 PM
<a href="">Whoops sry here it is...</a>
DevonX commented November 04, 2006 at 5:49 PM
noshenim commented July 15, 2008 at 10:49 PM
very usefull, 10
Iluvfuz commented August 24, 2008 at 10:06 PM
Oh no! It's only rate is 10/10 making it the highest rated example! 8/10, it's works well.