# shortest distance between two vectors

Whilst working on vectors I have come across a lot of problems like this. I am able to work it out for the shortest distance from a vector to a point, but not from a vector to a vector. Here is my usual method for a question asking the shortest distance from a vector (passing through $$A$$ and $$B$$) to a point $$C$$: $$\vec{OA}=a$$ $$\vec{OB}=b$$ $$\vec{OC}=c$$ Where $$O$$ is the origin. We know that the equation for a line passing through $$A$$ and $$B$$ is: $$\vec{r}=\mu(b-a)+a$$ we also know that at the closest distance a line from $$C$$ to $$\vec{r}$$ is perpendicular to $$\vec{r}$$. I would now define: $$\vec{r}=\begin{pmatrix}\mu(b_1-a_1)+a_1\\\mu(b_2-a_2)+a_2\\\mu(b_3-a_3)+a_3\end{pmatrix}=\begin{pmatrix}d_1\\d_2\\d_3\end{pmatrix}$$ so the distance from $$\vec{r}$$ to $$C$$ is: $$l=\sqrt{(d_1-c_1)^2+(d_2-c_2)^2+(d_3-c_3)^2}$$ now find the point at which $$\frac{dl}{d\mu}=0$$ solving for $$\mu$$ and subbing into the equation.

However, I am aware that there are much easier methods for find the point $$N$$ and the shortest distance $$|\vec{NC}|$$ involving the fact that $$\vec{r}\bullet\vec{NC}=0$$ or potentially cross product as well. Does anyone have a tutorial for this method? Also, how would I solve this same problem but finding the minimum distance between two vectors? Thanks

• It appears that by “distance to a vector” you really mean the distance to a line defined by a pair of points. As a hint, the situation is symmetric, so the points on each of two lines that are nearest to each other lie on a mutual perpendicular to the lines. – amd Jan 21 '19 at 0:19
• So if they are both perpendicular to the same line, then I can presume they are parallel – Henry Lee Jan 21 '19 at 0:47
• Not at all. The $x$-axis is perpendicular to both the $y$-axis and the line $(1,0,0)+t(0,0,1)$, but they are neither parallel nor do they intersect. – amd Jan 21 '19 at 2:59

For problems like this one you don't need derivatives.

Suppose that you know the coordinates of points $$A(x_A, y_A, z_A)$$, $$B(x_B, y_B, z_B)$$ and components of vectors $$\vec a=(a_x,a_y,a_z)$$, $$\vec b=(b_x,b_y,b_z)$$. The shortest distance between lines is represented with segment $$CD$$ and that segment is prependicular both to $$\vec a$$ and $$\vec b$$.

Now you have:

$$AC=\mu \vec a$$

$$BD=\lambda \vec b$$

$$\vec {CD} \bot \vec a \implies \vec{CD}\cdot \vec a=0$$

$$\vec {CD} \bot \vec b \implies \vec{CD}\cdot \vec b=0$$

...or, in scalar form:

$$x_C-x_A=\lambda a_x$$

$$y_C-y_A=\lambda a_y$$

$$z_C-z_A=\lambda a_z$$

$$x_D-x_B=\mu b_x$$

$$y_D-y_B=\mu b_y$$

$$z_D-z_B=\mu b_z$$

$$(x_D-x_C)a_x+(y_D-y_C)a_y+(z_D-z_C)a_z=0$$

$$(x_D-x_C)b_x+(y_D-y_C)b_y+(z_D-z_C)b_z=0$$

You have 8 linear equations and 8 unknowns: $$x_C, y_C, z_C, x_D, y_D, z_D, \lambda, \mu$$:

• From the first three equations express $$x_C, y_C, z_C$$ in terms of $$\lambda$$.
• From the next three equations express $$x_D, y_D, z_D$$ in terms of $$\mu$$.
• Replace all that into the last two equations and you have a system of two equations with two unknowns $$(\lambda,\mu)$$.
• Solve, find coordinates of points $$C,D$$
• Calculate distance CD.

For the shortest distance between a pair of lines $$L_1$$ and $$L_2$$ in $$\mathbb R^3$$, you can use symmetry and projections to develop a simple formula. You already know that the closest point on a line to a point $$P$$ not on the line lies on the perpendicular through $$P$$. So by symmetry, the nearest points to each other on a pair of lines must lie on a line $$M$$ that’s perpendicular to them both.

Working backwards for a moment, suppose that $$Q_1$$ and $$Q_2$$ are the nearest points to each other on the two lines. Since $$L_1\perp M$$, the orthogonal projection of any point on $$L_1$$ onto $$M$$ is $$Q_1$$ and similarly, the orthogonal projection of any point on $$L_2$$ onto $$M$$ is $$Q_2$$. Hence, given any pair of points on the two lines, the orthogonal projection onto $$M$$ of the segment joining them is $$\overline{Q_1Q_2}$$. This means that the shortest distance between $$L_1$$ and $$L_2$$ can be found by taking any pair of points on the respective lines and projecting them onto any line that’s perpendicular to $$L_1$$ and $$L_2$$.

Now, since $$M$$ is perpendicular to both $$L_1$$ and $$L_2$$, if you represent the two lines in parametric form as $$P_1+s\vec v_1$$ and $$P_2+t\vec v_2$$, respectively, then the cross product $$\vec v = \vec v_1\times\vec v_2$$ is a direction vector for $$M$$. For points on the lines, we can take $$P_1$$ and $$P_2$$, and so the distance between $$L_1$$ and $$L_2$$ is the length of the orthogonal projection of $$P_1-P_2$$ onto $$\vec v$$: $${|(P_1-P_2)\cdot(\vec v_1\times\vec v_2)| \over \|\vec v_1\times\vec v_2\|}.$$

You can also develop a simple formula for 3-D point-line distance using geometric considerations. Again, let the line be given in parametric form as $$P+t\vec v$$ and $$Q$$ be an arbitrary point. Consider the triangle formed by $$P$$, $$Q$$ and $$R=Q+\vec v$$. Taking $$\overline{QR}$$ as the base of the triangle, its area is $$\frac12bh = \frac12 \|\vec v\| h$$, but the altitude $$h$$ is the perpendicular distance from $$P$$ to the line. The area of this triangle is $$\frac12\|(P-Q)\times\vec v\|$$ (it’s half the area of the paralellogram defined by these two vectors), from which we have $$h = {|(P-Q)\times\vec v|\over\|\vec v\|}.$$