devfix-Blog
$$\newcommand{\vvv}[3]{\begin{pmatrix}#1\\#2\\#3\end{pmatrix}} \newcommand{\stimes}[0]{\small\times}$$

# Distances in linear algebra

## Between two points

Let $\vec{a}=\vvv{a_1}{a_2}{a_3}$ and $\vec{b}=\vvv{b_1}{b_2}{b_3}$ so the distance equals $d=\sqrt{(a_1-b_1)^2 + (a_2-b_2)^2 + (a_3+b_3)^2}$.

## Between point and line

Let $\vec{p}$ be the point and $\vec{l}=\vec{s}+t\vec{r}$ the line ($t\in\mathbb{R}$).
$$\color{white}d=\frac{|\vec{r}\times(\vec{p}-\vec{s})|}{|\vec{r}|}$$

### Derivation

$|\vec{r}\times(\vec{p}-\vec{s})|$ equals the area of the parallelogram the vectors $\vec{r}$ and $\overrightarrow{\text{SP}}=\vec{p}-\vec{s}$ span.
The term $|\vec{r}|d$ expresses that area too, where d is the height perpendicular to $\vec{r}$ in the same parallelogram and hence also the distance between $\vec{p}$ and $\vec{l}$. Both areas can be set equal and the expression rearranged to $d$.

## Between two lines

Let $\vec{l_1}=\vec{s_1}+t_1\vec{r_1}$ be the first and $\vec{l_2}=\vec{s_2}+t_2\vec{r_2}$ the second line ($t_1,t_2\in\mathbb{R}$).
The distance $d$ is the shortest distance between a point of each line:
$$d=\frac{|[\vec{r_1},\vec{r_2},(\vec{s_2}-\vec{s_1})]|}{|\vec{r_1}\times\vec{r_2}|}$$
Note: If the lines are parallel to each other the distance can be expressed as the distance between one line and any point of the other.

### Derivation

$|[\vec{r_1},\vec{r_2},(\vec{s_2}-\vec{s_1})]|$ equals the volume of the parallelepiped defined by the three vectors $\vec{r_1}$,$\vec{r_2}$ and $\overrightarrow{S_1S_2}=\vec{s_2}-\vec{s_1}$.
The term $|\vec{r_1}\times\vec{r_2}|d$ expresses the same volume: The area $|\vec{r_1}\times\vec{r_2}|$ is spanned by the two direction vectors $\vec{r_1}$ and $\vec{r_2}$ so that its accompanying height $d$ is perpendicular to both direction vectors and hence the distance between the two lines. Both volumes can be set equal and the expression rearranged to $d$.

## Between point and plane

Let $\vec{p}$ be a point and $\ \vec{e}\vec{n_0}=d\$ a plane in its Hesse normal form. If you don't know how to get there you should check out the planes article. \begin{align} \vec{p}&=\vec{e}+\lambda\vec{n_0}\ \ \ \ \ \ (\lambda\in\mathbb{R})\\ \lambda&=(\vec{p}-\vec{e})\vec{n_0}\\ \lambda&=\vec{p}\vec{n_0}-d \end{align} The absolute distance is now $|\lambda|$.