The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

I have a java question by benmiller2004-04-05 17:43:31
  Hmmm- trying to get UFies to do your CS homework?? by inittab2004-04-05 18:34:21
    Of course not by benmiller2004-04-05 18:43:44
      My solution: by benmiller2004-04-05 18:59:42
        Different solution by BrainBug 2004-04-05 20:33:27
Or rather a rough sketch thereof...
//Direction of line1
float dx0=x1-x0;
float dy0=y1-y0;

//Direction of line2
float dx1=x3-x2;
float dy1=y3-y2;

//Determinant
float det=dx0*dy1-dx1*dy0;

//for non-parallel lines det!=0
float s0=((x2-x0)*dy1-(y2-y0)*dx1)/det;

//s1 only needed because of line segments.
//For infinitely long lines s0 would've been enough
float s1=((y2-y0)*dx0-(x2-x0)*dy0)/det;

//for 0<=s0<=1 and 0<=s1<=1 intersection point
//is in line segment. Otherwise <0 means before start 
//point and >1 means after end point of respective line

//Intersection point
float px=dx0*s0+x0;
float py=dy0*s0+y0;

return new b2dPoint(px, py);
Feel free to replace the prose with Java code. Oh, and there's a code convention that suggests that b2dPoint should be B2dPoint ;)
[ Reply ]
          Code convention? by benmiller2004-04-05 20:44:06
            Hehe... by BrainBug2004-04-05 20:56:56
          Sign errors by BrainBug2004-04-05 21:32:05

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)