# Is there a better way to find the closest point on a line?

I'm given a question that asks: "Find the point on $L(x) = 4x-3$ that is closest to the point $(1,3)$."

My best guess was to find the derivative of the distances and set it equal to zero and solve to attempt to find a minimum. I come up with the derivative being$$f'(x)=\frac{1}{2}(17x^2-50x+37)^{-\frac{1}{2}}(34x-50)$$ And solving for x I end up with $50/34$ or about 1.4705. Now all I have to do is just plug that into the original linear equation. And when I graphed it out in desmos that appears to solve the problem correctly. My only issue is that my solution doesn't account for if there was a maximum instead of a minimum on the distance equation. Is there a more correct solution to this problem?

• Googling distance from a point to a line will get you a quicker way. As to your max versus min question, it is geometrically clear there is a unique min and no max. – André Nicolas Jul 28 '16 at 0:16
• @AJB Define "better". It certainly can be done without calculus. Find a perpendicular through (1,3), intersecting the line at S would do it. Distance formula on S and (1,3) is the final step – imranfat Jul 28 '16 at 0:26
• Please, try to make the titles of your questions more informative. E.g., Why does $a<b$ imply $a+c<b+c$? is much more useful for other users than A question about inequality. From How can I ask a good question?: Make your title as descriptive as possible. In many cases one can actually phrase the title as the question, at least in such a way so as to be comprehensible to an expert reader. You can find more tips for choosing a good title here. – Martin Sleziak Jul 28 '16 at 10:43
• Your original title "Is there a better way to do this?" said almost nothing about the question. I have edited it, but I think there is still space for improvement. – Martin Sleziak Jul 28 '16 at 10:43
• You could also rotate the coordinate system so that your line is parallel to one of the coordinate axis. – MrYouMath Aug 27 '16 at 22:58

Since your curve is a straight line with a slope of $4$, a perpendicular to this line will have a slope of $-1/4$.

Using point-slope form, a line with a slope of $-1/4$ going through $(1,3)$ will have the following equation:

$$y-3 = (-1/4)(x-1)$$

Solving for the intersection of this line and the original line will give you your answer.

EDIT: The comments noted that I jumped in using the perpendicular as the shortest distance without explaining why it was so. Here's a brief argument which can be worked out with more rigor if desired. Take the $x-y$ axes, which are perpendicular. Take the point $(0,5)$ which is $5$ units away from the origin, which lies on the $x$-axis and is also on the perpendicular from that point to the $x$ axis. If we go in either direction along the $x$ axis, the distance from $(0,5)$ to this point on the $x$ axis will increase, because now it's going along the hypotenuse of a right triangle defined by the origin, the point $(0,5)$, and the point of intersection, and this has to be longer than $5$ units. So, the perpendicular is the minimum distance.

• Strictly from a pedagogy standpoint, can we assume (for the purposes of this question only) that the shortest distance from a point to a line lies on its perpendicular? Yes, we know it to be true, but using that fact may be sidestepping the concept the question is intended to exercise. I get the sense that this is one of those homework questions where the process matters more than the answer itself. – Tristan Jul 28 '16 at 14:42
• @Tristan This is easily proved, as the distance to any other point forms the hypotenuse of a right triangle with the perpendicular as one of its legs. – f'' Jul 28 '16 at 16:30
• @f'' Of course it is, but for the sake of respecting the teaching process (I am of course making a big assumption here), cutting right to this answer without demonstrating why this is the case may yield less value than looking at the "minimizing the distance" approach. In particular, cutting right to the perpendicular line answer does nothing to teach why that is the correct answer. – Tristan Jul 28 '16 at 17:43
• @Tristan That's a good point. I added explanation to my answer. – John Jul 28 '16 at 20:05
• To say that (0, 5) is a distance of 5 from the x-axis seems like circular reasoning to me. – msinghal Jul 29 '16 at 1:59

You can make the problem simpler since minimizing the distance is the same as minimizing the square of the distance.

Then $$D^2=(x-1)^2+(4x-3-3)^2=17 x^2-50 x+37$$ $$\frac{d(D^2)}{dx}=34 x-50$$ $$\frac{d^2(D^2)}{dx^2}=34 > 0$$

So the first derivative cancels if $x=\frac{25}{17}$ to which cooresponds $y=\frac{49}{17}$, $D^2=\frac{4}{17}$. The second derivative test confirms that this is a minimum.

My only issue is that my solution doesn't account for if there was a maximum instead of a minimum on the distance equation.

Well, you can solve this problem by invoking the "first derivative test".

You got $f'(x)=0$ if $x=\frac{50}{34}$. Analogously:

• $f'(x)<0$ if $x<\frac{50}{34}$
• $f'(x)>0$ if $x>\frac{50}{34}$

Thus, $f$ is decreasing on $(-\infty,\frac{50}{34})$ and increasing on $(\frac{50}{34},\infty)$. So, $f$ has a minimum at $\frac{50}{34}$.

• wouldn't that be the second derivative test, if you're looking at changing signs of $f'$ ? – costrom Jul 28 '16 at 16:09
• @costrom the Second Derivative Test looks at $f''$ at a point. The test here looks at $f'$ on intervals – AakashM Jul 29 '16 at 7:28

Use the fact that the distance from a point $(x_0, y_0)$ to a line $ax + by + c = 0$ is given by $$\frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}$$ Plugging in the numbers in question, we get $$\frac{|-4(1) + 1(3) + 3|}{\sqrt{1^2 + 4^2}} = \frac{2\sqrt{17}}{17}.$$

If you want a proof of the formula, check here.

A simple, Linear Algebra approach. First,represent the intercept, the point and the direction of the line as vectors.

$p=<0,-3>,q=<1,3>,v=<1,4>$

Create the vector projection of the line between $p$ and $q$ onto $\vec{v}$

$\vec{u}=\vec{q}-\vec{p}, w=\frac{\vec{u}.\vec{v}}{\vec{v}.{\vec{v}}}\vec{v}$

Giving $\vec{u}=<1,6>,\vec{w}=<\frac{25}{17},\frac{100}{17}>$ then

the closest point is given by $r=\vec{p}+\vec{w} = <1,-3>+<\frac{25}{17},\frac{49}{17}>$

If you have the cartesian equation of the straight line $L$, you have a normal vector $\vec n$ to $L$. The projection $H$ of a point $A$ is the point $H$ of the line passing by $A$ directed by this normal vector, $A+t\,\vec n, \enspace t\in\mathbf R$, which satisfies the equation of $L$.

Here, the equation is $\;4x-y-3=0$, $\;\vec n=(4,-1)$, $A=(1,3)$, $H=(1+4t,3-t)$, hence the parameter $t$ is determined by the equation $$3-t=4(1+4t)-3\iff t=\frac 2{17}.$$

The closest point on a line is where a circle with an origin at the point touches the line. To find the radius of the circle, solve the equations for a circle and a line where there is a single solution.

Since the curve is linear, we can use linear algebra just fine.

Notice that $(0,-3)$ is on the line by putting $x=0$ to get $L(0)=-3$. Translate everything on the plane so that the line passes through the origin, giving a new line $L'(x)=4x$. A choice of this translation vector is $(0,3)$ as found above. The point $(1,3)$ is translated to $(1,6)$.

Now project the point $(1,6)$ onto $L'$ by using dot product. Explicitly, you evaluate the following$$\frac{\langle(1,6),(1,4)\rangle}{1^2+4^2}(1,4)$$ to obtain the vector $$(\frac{25}{17},\frac{100}{17}),$$ which is the point on $L'$ being closest to $(1,6)$. Translate back to the original position, giving $$(\frac{25}{17},\frac{100}{17})-(0,3)=(\frac{25}{17},\frac{49}{17})$$ being the point on $L$ closest to $(1,3)$.