A line in 3d will be given by its $x,y,$ and $z$ components, and they might be given as three equation, or as a vector equation. For example \[ L:\ \left(x=4t+2,\,y=2t-7,\ z=-3t-3\right) \] The same line could be written as a vector this way. \[ \left(\begin{array}{c} x\\ y\\ z \end{array}\right)=\left(\begin{array}{c} 2\\ -7\\ -3 \end{array}\right)+t\left(\begin{array}{c} 4\\ 2\\ -3 \end{array}\right) \] Also, if $P=(2,-7,-3)$ and $\mathbf{u}=(4,2,-3),$ then the line might be \[ \mathbf{X}=P+t\cdot\mathbf{u}. \] A plane will probably be written as \[ 4x+2y-3z=3. \] But could just as well be written as \[ \left(\begin{array}{c} 4\\ 2\\ -3 \end{array}\right)\cdot\left(\begin{array}{c} x\\ y\\ z \end{array}\right)=\left(\begin{array}{c} 4\\ 2\\ -3 \end{array}\right)\cdot\left(\begin{array}{c} 2\\ -7\\ -3 \end{array}\right) \] which would probably be shortened to \[ \mathbf{u}\cdot\mathbf{X}=\mathbf{u}\cdot P \] to describe the plane with normal $\mathbf{u}$ which includes point $P.$ The operation here is a dot product. So, \[ \left(\begin{array}{c} 4\\ 2\\ -3 \end{array}\right)\cdot\left(\begin{array}{c} x\\ y\\ z \end{array}\right)\text{ means }4x+2y-3z. \]

The essence of method 1 is to find the intersection of the line and the plane orthogonal to the line where that plane contains the external point. See the figure in the example below. We are given both the line equation and the point, $P.$ We will need to know one point on the line. It can be deduced from the line equation, or we can input any scalar value $t,$ and calculate a point. Call it $A.$

- Name a point on the line. Call it $A.$ Get its coordinates.
- Identify the direction vector of the line. Call it $\mathbf{u}.$ If the line was given as being between points $A$ and $B,$ then \[ \mathbf{u}=(B-A)=\left(\begin{array}{c} B_{x}-A_{x}\\ B_{y}-A_{y}\\ B_{z}-A_{z} \end{array}\right). \]
- Write the line equation. Even if it was previously given. \begin{equation} \left(\begin{array}{c} x\\ y\\ z \end{array}\right)=\left(\begin{array}{c} A_{x}\\ A_{y}\\ A_{z} \end{array}\right)+t\cdot\left(\begin{array}{c} u_{x}\\ u_{y}\\ u_{z} \end{array}\right).\label{eq:eqn for t} \tag{"the line equation"} \end{equation}
- Write the plane equation that has normal, $\mathbf{u}$ and passes through $P.$ \[ \mathbf{X}\cdot\mathbf{u}=\mathbf{u}\cdot P. \] That is, \[ \left(\begin{array}{c} x\\ y\\ z \end{array}\right)\cdot\left(\begin{array}{c} u_{x}\\ u_{y}\\ u_{z} \end{array}\right)=\left(\begin{array}{c} u_{x}\\ u_{y}\\ u_{z} \end{array}\right)\cdot\left(\begin{array}{c} P_{x}\\ P_{y}\\ P_{z} \end{array}\right). \]
- Find the intersection of the line and plane. That point will be the place on the line which when connected to point $P$ forms an orthogonal segment. The length of that segment is the distance from $P$ to the line.
- Substitute the 3 equations from the line equation into the plane equation. Remember that this is a dot product equation. \[ \left(\begin{array}{c} A_{x}+t\cdot u_{x}\\ A_{y}+t\cdot u_{y}\\ A_{z}+t\cdot u_{z} \end{array}\right)\cdot\left(\begin{array}{c} u_{x}\\ u_{y}\\ u_{z} \end{array}\right)=\left(\begin{array}{c} u_{x}\\ u_{y}\\ u_{z} \end{array}\right)\cdot\left(\begin{array}{c} P_{x}\\ P_{y}\\ P_{z} \end{array}\right) \] \[ (A_{x}+t\cdot u_{x})(u_{x})+(A_{y}+t\cdot u_{y})(u_{y})+(A_{z}+t\cdot u_{z})(u_{z})=u_{x}P_{x}+u_{y}P_{y}+u_{z}P_{z}. \]
- Solve for $t.$
- Plug the found value for $t$ back into the line equation, eqn. \ref{eq:eqn for t} and calculate the intersection point. Call it $E.$
- Calculate the distance between $P$ and $E$ using the distance equation. \[ dist=|P-E|=\sqrt{\left(P_{x}-E_{x}\right)^{2}+\left(P_{y}-E_{y}\right)^{2}+\left(P_{z}-E_{z}\right)^{2}} \]

The essence of method 2 is to write an expression, $\mathbf{v,}$ for the vector from the external point to the line, $\ell$. Then notice that said vector will dot product with the line direction vector to yield zero. Solve that equation for $t,$and then put the $t$ value into equation $\mathbf{v}$ to get the orthogonal direction vector. Alternatively, put the $t$ value into the line, $\ell,$ to get the intersection point.

Given the line between points $A=(-5,2,3)$ and $B=(-1,4,2),$find
the perpendicular distance to the line from point $P=(1,2,1).$
Let $n$ be the direction vector of the line. So
\[
n=(B-A)=\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)
\]
and the line equation is
\[
\ell:\ \left(\begin{array}{c}
x\\
y\\
z
\end{array}\right)=\left(\begin{array}{c}
-5\\
2\\
3
\end{array}\right)+t\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)
\]
A vector $\mathbf{v},$ from point $P$ to the line would be
\[
\begin{aligned}\mathbf{v} & =\left(A+t\cdot n\right)-P\\
& =\left[\left(\begin{array}{c}
-5\\
2\\
3
\end{array}\right)+t\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)\right]-\left(\begin{array}{c}
1\\
2\\
1
\end{array}\right)
\end{aligned}
\]
which can be dot product with $n$ to equal zero. Since the dot product
of orthogonal vectors is zero.
\[
\left(\left[\left(\begin{array}{c}
-5\\
2\\
3
\end{array}\right)+t\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)\right]-\left(\begin{array}{c}
1\\
2\\
1
\end{array}\right)\right)\cdot\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)=0
\]
\[
\begin{aligned}\left(-5+4t-1\right)4+\left(2+2t-2\right)2+\left(3-t-1\right)\left(-1\right) & =0\\
\left(-20+16t-4\right)+\left(4+4t-4\right)+\left(-3+t+1\right) & =0\\
-24-2+21t & =0\\
-26+21t & =0\\
t & =\frac{26}{21}
\end{aligned}
\]
Solve for $t:$ $t=26/21.$
Put this $t$ value into $\mathbf{v}.$
\[
\mathbf{v}=\left[\left(\begin{array}{c}
-5\\
2\\
3
\end{array}\right)+\left(\frac{26}{21}\right)\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)\right]-\left(\begin{array}{c}
1\\
2\\
1
\end{array}\right)=\left(\begin{array}{c}
-22/21\\
52/21\\
16/21
\end{array}\right)\Leftarrow\text{Perpendicular Vector}
\]
Or,
\[
\text{Intersection Point}:\ \left(\begin{array}{c}
-5\\
2\\
3
\end{array}\right)+\left(\frac{26}{21}\right)\left(\begin{array}{c}
4\\
2\\
-1
\end{array}\right)=\left(\begin{array}{c}
-1/21\\
94/21\\
37/21
\end{array}\right)
\]

The essence of method 3 is vector projection. We will build a right triangle in the plane of three points. Two of the points, $A$ and $E$ will be on the line and the third point, $P$ will be external to the line. Point $A$ on the line is arbitrary. Point $P$ is the external point from which we will try to draw a perpendicular, and point $E$ is the intersection of the line and the perpendicular from $A.$

Point $E$: \[ E=A+\frac{\left\Vert \mathbf{p}\cdot\mathbf{n}\right\Vert }{\mathbf{n\cdot n}}\cdot\mathbf{n} \] Distance $d$ can be computed with two options: \[ d=\frac{\mathbf{\left\Vert p\times n\right\Vert }}{|\mathbf{n}|} \] or \[ d=|E-P|. \]