There are several ways that you can attack this problem. I'm going to use a parameterized approach similar to the one used for Problem 29. Line-line intersection.
Suppose the point is (px, py) and the line is given by p0 + t × v. Then the distance between the point and a point on the line is given by the following:
We need to find the value of t that minimizes this equation. You can do that with one trick and a little calculus.
The trick is to note that the minimum of this equation has the same X coordinate that minimizes the equation squared. The following shows the squared equation:
Here comes the calculus. To minimize ...