Given a line segment and a point P, this returns the point on the segment that is closest to P.
nearestPoint = PointOnSegmentNearestToPoint( A, B, P );
This function will return A or B if P is beyond these two points.