I think that what you really want is the distance of a point to a segment, and not the distance to a line. Because a line is infinite, and the shortest distance of a point to a line might fall outside your segment.

In the case below, the distance of the point C to the line AB is CP. But P is outside of your segment, and what you really want is CA and not CP.

` /
x (B)
/
/
/
x (C) x (A)
`. /
`. /
`x
/ (P)
/
/
`

So, you must find the coordinate of P (the distance to the line) then check if P is outside of your segment. If it's outside, then you compute CA and CB and take the shortest.

Comment onRe: Algorithm: point with N distance of a line between two other pointsDownloadCode