Let a line in three dimensions be specified by two points and lying on it, so a vector along the line is given by
(1)The squared distance between a point on the line with parameter and a point is therefore(2)To minimize the distance, set and solve for to obtain
(3)where denotes the dot product. The minimum distance can then be found by plugging back into (2) to obtain
(4)(5)