# Distance between points and lines

Let P=(3,1,4), Q=(1,2,5), R=(0,0,1) and S=(4,3,6). Let A be the line passing through P and Q, and let B be the line passing through R and S.

a) What is the distance between R and A?

b) What is the distance between A and B?

So I tried to use the distance between points formula but it did not yield the correct answer. Also, how exactly would I measure the distance between a point and a line. What point on the line would I be measuring against?

Any help?

• distance between point and line is a perpendicular from point to line Nov 5 '17 at 3:04

a) $\frac{\sqrt{165}}{3}$
b) $\frac{\sqrt3}{3}$
The lines can be represented as follows: \begin{align} a(x) &= a_0 + u_a x, \\ b(x) &= b_0 + u_b y. \end{align} Here, $a_0$ can be $P$ or $Q$ (or any linear combination) and $b_0$ can be $R$ or $S$. I choose for $a_0=P$ and $b_0=R$. The unit vector $u_a$ is the normalized difference between $Q$ and $P$ and the unit vector $u_b$ is the normalized difference between $S$ and $R$. As a result, we have: $$u_a=\frac{1}{\sqrt{6}}\begin{bmatrix}-2 \\ 1 \\ 1 \end{bmatrix}, \quad u_b=\frac{1}{5\sqrt{2}}\begin{bmatrix} 4 \\ 3 \\ 5 \end{bmatrix}$$
Observe that $u_a$ and $u_b$ are perpendicular (i.e. $u_a \cdot u_b = 0$). This will make live easier. We can solve the problem by minimizing the distance between $a(x)$ and $b(y)$ with respect to $x$ and $y$. To make our problem easier, I will make use of another coordinate system. I need a transformation matrix for this. Let this transformation matrix be denoted by $Q^T$, such that the first two columns of $Q$ are $u_a$ and $u_b$, respectively. To find the third column, I use an arbitrarily chosen vector $c=\begin{bmatrix}1&0&0\end{bmatrix}^T$ and substract the projections of $c$ on $u_a$ and $u_b$: $$c - u_a \frac{u_a \cdot c}{u_a \cdot u_a} - u_b \frac{u_b \cdot c}{u_b \cdot u_b}= \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} - \frac{1}{6} \begin{bmatrix} -2 \\ 1 \\ 1 \end{bmatrix} - \frac{1}{10} \begin{bmatrix} 4 \\ 3 \\ 5 \end{bmatrix} = \frac{1}{15} \begin{bmatrix} -1 \\ -7 \\ 5 \end{bmatrix}.$$ Normalized gives $$u_c = \frac{\sqrt{3}}{15}\begin{bmatrix} -1 \\ -7 \\ 5 \end{bmatrix}.$$ To answer your first question, we want to minimize $||a(x)-R||$. The result does not change use the transformation, so we can minimize $||Q^T a(x) - Q^TR||$. This gives: \begin{align} Q^T a(x) - Q^TR &= Q^Ta_0 + Q^T u_a + Q^T R \\ &= \begin{bmatrix} -\frac{1}{\sqrt{6}} \\ \frac{7}{\sqrt{2}} \\ \frac{2\sqrt{3}}{3} \end{bmatrix} + \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}x- \begin{bmatrix} \frac{1}{\sqrt{6}} \\ \frac{1}{\sqrt{2}} \\ \frac{\sqrt{3}}{3} \end{bmatrix} \\ &= \begin{bmatrix} x - \frac{2}{\sqrt{6}} \\ 3\sqrt{2} \\ \frac{\sqrt{3}}{3} \end{bmatrix}. \end{align} It is easy to see that a minimal distance is at $x=\frac{2}{\sqrt{6}}$ and that this distance equals $$\sqrt{\left(3\sqrt{2}\right)^2 + \left(\frac{5\sqrt{3}}{15}\right)^2} = \frac{\sqrt{165}}{3}.$$ To answer the second question, note that we want to minimize $||a(x)-b(y)||$. Again, this is similar to minimizing $||Q^Ta(x)-Q^Tb(y)||$: \begin{align} ||Q^Ta(x)-Q^Tb(y)|| &= Q^Ta_0 + Q^Tu_ax - Q^Tb_0 - Q^Tu_by \\ &= \begin{bmatrix} -\frac{1}{\sqrt{6}} \\ \frac{7}{\sqrt{2}} \\ \frac{2\sqrt{3}}{3} \end{bmatrix} + \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}x- \begin{bmatrix} \frac{1}{\sqrt{6}} \\ \frac{1}{\sqrt{2}} \\ \frac{\sqrt{3}}{3} \end{bmatrix} - \begin{bmatrix}0\\1\\0\end{bmatrix}y \\ &= \begin{bmatrix} x - \frac{2}{\sqrt{6}} \\ y+3\sqrt2 \\ \frac{\sqrt3}{3} \end{bmatrix}. \end{align} It is easy to see that the first two entries can be zero if $x$ and $y$ are chosen appropriately. So the distance from $A$ and $B$ is $$\frac{\sqrt3}{3}.$$