The distance of a point to a segment is the length of the shortest line joining the point to a point on the segment. This Demonstration depicts this shortest line as dotted. The measurements are normalized so that the point starts at a distance of 1 to the segment.

To compute the distance from point p to segment ab (all as complex numbers) compute first z=(p-a)/(b-a). If 0 ≤ Re[z] ≤ 1 then the distance is equal to Abs[Im[z](b-a)]. If not, it is equal to the smallest of the distances from p to a or to b.