Rotation of a 3-vector

We'll find an expression for the rotation of a vector $\mathbf{r}=(x_1,x_2,x_3)$ around an axis with unit vector $\mathbf{n}=(n_1,n_2,n_3)$ through an angle $\theta$, as shown in Figure .
The vector $\mathbf{r}$ is analysed in two components
\begin{equation}
\mathbf{r}=\mathbf{r}_\|+\mathbf{r}_\bot
\tag{01}
\end{equation}
one parallel and the other normal to axis $\mathbf{n}$ respectively
\begin{eqnarray}
&\mathbf{r}_\| &=(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\mathbf{n}
\tag{02a}\\
&\mathbf{r}_\bot &=(\mathbf{n}\times\mathbf{r})\times \mathbf{n}= \mathbf{r}-(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\mathbf{n}
\tag{02b}
\end{eqnarray}
If $\mathbf{r}$ is rotated to $\mathbf{r}^{\prime}$
\begin{equation}
\mathbf{r}^{\prime}=\mathbf{r}^{\prime}_\|+\mathbf{r}^{\prime}_\bot
\tag{03}
\end{equation}
then the parallel component remains unchanged
\begin{equation}
\mathbf{r}^{\prime}_\|=\mathbf{r}_\| =(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\mathbf{n}
\tag{04}
\end{equation}
while the normal component $\mathbf{r}_\bot =(\mathbf{n}\times\mathbf{r})\times \mathbf{n}$ is rotated by the angle $\theta$, so having in mind that this vector is perpendicular to $\mathbf{n}\times\mathbf{r}$ and of equal norm
\begin{equation}
\left\|(\mathbf{n}\times\mathbf{r})\times \mathbf{n}\right\|=\left\|\mathbf{n}\times\mathbf{r}\right\|
\tag{05}
\end{equation}
we find the expression, see Figure below
\begin{eqnarray}
\mathbf{r}^{\prime}_\bot &=& \cos\theta\left[(\mathbf{n}\times\mathbf{r})\times \mathbf{n}\right]+\sin\theta\left[\mathbf{n}\times\mathbf{r}\right]\nonumber\\
&=& \cos\theta\left[\mathbf{r}-(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\mathbf{n}\right]+\sin\theta\left[\mathbf{n}\times\mathbf{r}\right]\nonumber\\
&=& \cos\theta\;\mathbf{r}-\cos\theta(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\mathbf{n}+\sin\theta\left[\mathbf{n}\times\mathbf{r}\right]
\tag{06}
\end{eqnarray}
and so finally the vector expression
\begin{equation}
\bbox[#FFFF88,12px]{\mathbf{r}^{\prime}= \cos\theta \cdot\mathbf{r}+(1-\cos\theta)\cdot(\mathbf{n}\boldsymbol{\cdot}\mathbf{r})\cdot\mathbf{n}+\sin\theta\cdot(\mathbf{n}\times\mathbf{r})}
\tag{07}
\end{equation}
From this the $3\times3$ rotation matrix reads
\begin{equation}
\mathbb{A}\left(\mathbf{n}, \theta\right) = \text { 3D-rotation around axis} \:\:\mathbf{n}=\left(n_{1}, n_{2},n_{3}\right)\:\: \text{through angle} \:\:\theta
\end{equation}
\begin{equation}
=
\bbox[#FFFF88,12px]{
\begin{bmatrix}
\cos\theta+(1-\cos\theta)n_1^2&(1-\cos\theta)n_1n_2-\sin\theta n_3&(1-\cos\theta)n_1n_3+\sin\theta n_2\\
(1-\cos\theta)n_2n_1+\sin\theta n_3&\cos\theta+(1-\cos\theta)n_2^2&(1-\cos\theta)n_2n_3-\sin\theta n_1\\
(1-\cos\theta)n_3n_1-\sin\theta n_2&(1-\cos\theta)n_3n_2+\sin\theta n_1&\cos\theta+(1-\cos\theta)n_3^2
\end{bmatrix}}
\tag{08}
\end{equation}
