ClosestPointOnLine

function ClosestPointOnLine(const pt, linePt1, linePt2: TPointD): TPointD;

Returns the point on the line (defined by linePt1 and linePt2) that's closest to 'pt'. (Note: the returned point may be outside the line segment defined by the two line points.)