The normal way of computing it is this (and requires no sqrts ;) Notation: A and B are the end points, C is the arbitrary point, D is the closest point on the segment
u = (C-A) <dot> (B-A) / ||B-A||^2 if u < 0 D = A else if u > 1 D = B else D = A + u * (B-A) -M Amir Taaki wrote: > aha, > > AB is the line segment > ^ is unit vector (we use this in england above vector for unit vector) > > C is the point > > On Sun, Jul 27, 2008 at 11:05 PM, Marten Svanfeldt (dev) > <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote: > > Hi, > > What is A, B, C and AB? I assume you use ^ to indicate unit vector (a > bit strange imo ;) > > -M > > Amir Taaki wrote: > > Hi! > > > > So right now to find the closest point on a line segment I > project the > > vectors. Then to see if the point is outside the segment I do, > > > > c = C - A > > if (c^ = AB^) > > { > > if (|c| < |AB|) => lies inside segment > > else > > return B > > } > > else > > return A > > > > Is there a way to do it without a sqrt? the one needed to > calculate the > > unit vectors? > > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > This SF.Net email is sponsored by the Moblin Your Move > Developer's challenge > > Build the coolest Linux based applications with Moblin SDK & win > great prizes > > Grand prize is a trip for two to an Open Source event anywhere in > the world > > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > <http://moblin-contest.org/redirect.php?banner_id=100&url=/> > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Crystal-main mailing list > > [email protected] > <mailto:[email protected]> > > https://lists.sourceforge.net/lists/listinfo/crystal-main > > Unsubscribe: mailto:[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>?subject=unsubscribe > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > <http://moblin-contest.org/redirect.php?banner_id=100&url=/> > _______________________________________________ > Crystal-main mailing list > [email protected] > <mailto:[email protected]> > https://lists.sourceforge.net/lists/listinfo/crystal-main > Unsubscribe: mailto:[EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>?subject=unsubscribe > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Crystal-main mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/crystal-main > Unsubscribe: mailto:[EMAIL PROTECTED] ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Crystal-main mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/crystal-main Unsubscribe: mailto:[EMAIL PROTECTED]
