# How to find a point on a line closest to another given point?

Given the line $x+2=\frac{y+4}{2}=\frac{z-5}{-2}$
I want to find the closest point on this line to $(1,1,1)$

I suppose the details here don't matter but in general how is this done? We need a vector perpendicular to the line but that also reaches $(1,1,1)$.

-
A line and a point not on that line determine a plane, so you need to find the line perpendicular to your line on that plane. –  Harry Stern Dec 5 '10 at 23:47
So I can pick any other line that does not intersect with the above line? –  fdart17 Dec 5 '10 at 23:52

One point on the line is (-2,-4,5) and another is (0,0,1) (found by setting the equation to 0, then to 2). So the general point is (-2t, -4t,1+4t). You want the dot product of the vector from a point on the line to (1,1,1) and a vector along the line to be zero. So $$(-2,-4,4)\cdot(-2t-1,-4t-1,4t)=0$$ $$4t+2+16t+4+16t=0$$ $$t=\frac{-1}{6}$$ And the point is $$(\frac{1}{3},\frac{2}{3},\frac{1}{3})$$

-

One method is to parametrize the line. So $$\vec{r}(t) = (t-2)\hat{\imath} + (2t-4)\hat{\jmath} + (-2t+5)\hat{k}$$ We can then define the real-valued function $d(t)$ representing the distance from the line to $(1,1,1)$ for any value of $t$. Hence $$d(t) = \sqrt{(t-3)^2 + (2t-5)^2 + (-2t+4)^2} = \sqrt{9t^2 - 42t + 40}$$ To find the minimum, it's now only a single variable optimization problem. So by standard procedure, look at $d'(t)$ $$d'(t) = \frac{9t - 21}{\sqrt{9t^2 - 42t + 40}}$$ The critical point occurs at $t = \frac{7}{3}$, so the closest point is $\vec{r}(\frac{7}{3}) = (\frac{1}{3},\frac{2}{3},\frac{1}{3})$.

-

Using multi-variable calculus you would write a formula for distance from the point (1,1,1) to the arbitrary point (x,y,z) (this second points needs to satisfy your equation since it lies on the line). You would then apply the multi-variable optimization procedure: Find the critical points of this functions (those points where both partial derivatives equal zero or those points where either partial derivative is undefined) and examine these to find the minimum value for distance.

If you do want to use linear algebra, a vector from the point (x,y,z) (on the line) to the point (1,1,1) is $<1-x,1-y,1-z>$ Now take a directional vector from your line and compute the dot product of this with $<1-x,1-y,1-z>$. As you said, this dot product should be zero so solve for x,y, and z.

-
I don't know multi-variable calculus yet! But thanks. I was in fact thinking about optimizing but then I would have to relate this to projections and this would get super messy and probably incalculable. –  fdart17 Dec 5 '10 at 23:49

First express $y$ and $z$ in terms of $x$: $y=y(x)$, $z=z(x)$. You want to find the minimum of $f(x) = (x-1)^2 + (y(x)-1)^2 + (z(x)-1)^2$. Noting that $f(x)$ is a parabola, you should find easily the (single) $x$ that minimizes $f(x)$ (global minimum). Then, you get $y(x)$ and $z(x)$ by substitution.

EDIT: Explicitly, $y(x)=2x$ and $z(x)=1-2x$. This leads to $f(x)=9x^2-6x+2$, whose minimum is obtained at $x=1/3$. The solution is then $(x,y,z)=(1/3,2/3,1/3)$, as already given in two previous answers.

-