2

Find the point on the line $x=[1,1,1]+t[1,2,3],\ t \in \mathbb{R}$, that is closest to the point $[0,0,1]$.

How do you find this point?

Thank you very much.

Jing
  • 139
  • Decent question, but the title doesn't make sense. The title should make sense without having to read the question. Try "Find point on line" etc. – Stefan Smith Oct 01 '13 at 02:33

4 Answers4

4

Denote that point as $A(x_1,x_2,x_3) = [1+t, 1+2t, 1+3t]$, so $$ d^2 = (t+1)^2+(2t+1)^2 + 9t^2 $$ should have vanishing first derivative. $$ \left ( d^2 \right )' = 2(t+1) + 4(2t+1) + 18t = 28t + 6 = 0 \implies t = -\frac 3{14} $$ Since second derivative is positive everywhere, that point is minimum. $$ A = \left [ 1 - \frac 3{14}, 1 - \frac 37, 1 - \frac 9{14} \right ] = \frac 1{14}\left [11, 8, 5 \right ] $$

Kaster
  • 9,722
3

I discuss the details elsewhere [ http://recklessreckoner.blogspot.com/2013/02/perpendicular-distance-ii-its-all.html ] , but it can be shown that the perpendicular distance from an external point to a point on the line is the shortest distance to the line (the number of dimensions involved is immaterial). So the vector from the closest point on the line $ \ (1,1,1) \ + t \ < 1 , 2 , 3 > \ $ to the point $ \ (0, 0, 1 ) \ $ is perpendicular to the direction of the line $ \ < 1, 2, 3 > \ $ . So we can solve the dot-product equation

$$ < 1 , 2 , 3 > \ \cdot \ < (1 + t) - 0 \ , \ (1 + 2t) - 0 \ , \ (1 + 3t) - 1 > \ = \ 0 $$

$$ \Rightarrow \ ( 1 + t ) + ( 2 + 4t ) + 9t \ = 0 \ , $$

which leads to the same result for $ \ t \ $ and for the coordinates of the closest point as found by Kaster , $ \ ( \ \frac{11}{14} \ , \ \frac{8}{14} \ , \ \frac{5}{14} \ ) \ $ .

colormegone
  • 10,842
  • Thank you. Can we use projection to solve this question? – Jing Oct 01 '13 at 02:38
  • Well, the projection of orthogonal lines onto each other is zero, so if I'm understanding what you're asking, looking for zero projection does the same thing. – colormegone Oct 01 '13 at 03:20
0

This question already has some perfectly valid answers, however, I was looking for something that can easily be translated into code and should work for any line and point combination that is unknown at compile time.

A different way to view this problem is the intersection of a plane and a line since the minimal distance is always perpendicular to the line and all lines perpendicular to a line in 3D space form a plane.

This means you take the direction of the line and use it as the plane normal of a plane going through the point for which you want to find the closest point on the line.

In the following, $p_0$ is the point for which we want to find the closest point to the line given by its origin $l_0$ and its direction $l$ (and $\cdot$ is the dot product).

$$x=l_0 + t * l \quad \text{with} \quad t \in \mathbb{R}$$

We form a plane where the set of points $p$ on the plane fulfills

$$(p-p_0) \cdot l = 0$$

Now, we can simply find the closest point by finding the point where the line and the plane cross which is a single point because the line is orthogonal to the plane by definition. This is done by first finding the distance of the line's origin to the plane:

$$t = \frac{(p_0 - l_0) \cdot l}{l \cdot l}$$

Inserting t into the line equation will give us the closest point.

Example with the given values: $$ l_0 = \begin{bmatrix}1 \\ 1 \\ 1\end{bmatrix} \quad l = \begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix} \quad p_0 = \begin{bmatrix}0 \\ 0 \\ 1\end{bmatrix} \quad $$ $$ t_{closest} = \frac{ (\begin{bmatrix}0 \\ 0 \\ 1\end{bmatrix} - \begin{bmatrix}1 \\ 1 \\ 1\end{bmatrix}) \cdot \begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix}} {\begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix} \cdot \begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix}} = \frac{(-1)*1+(-1)*2+0*3}{1*1+2*2+3*3} = \frac{-3}{14}\\ x_{closest} = \begin{bmatrix}1 \\ 1 \\ 1\end{bmatrix} + \frac{-3}{14} * \begin{bmatrix}1 \\ 2 \\ 3\end{bmatrix} = \begin{bmatrix}\frac{11}{14} \\ \frac{8}{14} \\ \frac{5}{14}\end{bmatrix} $$ For more on this see the wikipedia page on line plane intersection

0

I also ran into this problem while programming, and here's the formula I came up with:

$$\vec{c} = \left(\vec{u} \cdot (\vec{p_0} - \vec{p_1})\right)*\vec{u} + \vec{p_1}$$

where $\vec{c}$ is the point you're trying to find on the line, $\vec{p_0}$ is the given point off the line, $\vec{p_1}$ is a point on the line, and $\vec{u}$ is a unit vector in the direction of the line. Essentially, the formula projects the vector from $\vec{p_1}$ to $\vec{p_0}$ onto the line, then adds the resulting vector, which is relative to $\vec{p_1}$, to $\vec{p_1}$ to get the absolute position.

Here's how it can be applied to the problem at hand:

\begin{align*} \vec{p_0} &= \left[ \matrix{0 \cr 0 \cr 1} \right] \\ \vec{p_1} &= \left[ \matrix{1 \cr 1 \cr 1} \right] \\ \vec{u} &= \frac{1}{\sqrt{14}} \left[ \matrix{1 \cr 2 \cr 3} \right] \\ \vec{c} &= \left(\vec{u} \cdot (\vec{p_0} - \vec{p_1})\right)*\vec{u} + \vec{p_1} \\ &= \left(\frac{1}{\sqrt{14}} \left[ \matrix{1 \cr 2 \cr 3} \right] \cdot \left[ \matrix{-1 \cr -1 \cr 0} \right]\right) * \frac{1}{\sqrt{14}} \left[ \matrix{1 \cr 2 \cr 3} \right] + \vec{p_1} \\ &= -\frac{3}{14} \left[ \matrix{1 \cr 2 \cr 3} \right] + \left[ \matrix{1 \cr 1 \cr 1} \right] \\ &= \frac{1}{14}\left[ \matrix{11 \cr 8 \cr 5} \right] \end{align*}

It can be a bit annoying to do by hand, but it's definitely easy to code!