Expression of Rotation Matrices

 The matrix \(R=R(x,y,z,\theta)\) that rotates by an angle \(\theta\) around a unit vector \(V=(x,y,z)\) can be expressed as
$$R=
\begin{pmatrix}
x^2(1-\cos\theta) + \cos\theta &
x y(1-\cos\theta) – z \sin\theta &
z x (1-\cos\theta) + y \sin\theta\\
x y (1-\cos\theta) + z \sin\theta&
y^2 (1-\cos\theta) + \cos\theta&
y z (1-\cos\theta) – x \sin\theta\\
z x (1-\cos\theta) – y \sin\theta&
y z (1-\cos\theta) + x \sin\theta&
z^2 (1-\cos\theta) + \cos\theta
\end{pmatrix}
$$This is known as the Rodrigues’ rotation formula.

 The sum of the diagonal components of the above matrix is \(S = 1 + 2\cos\theta\). Using this property, we can find the angle between two rotation matrices \(M_1,M_2\) that preserve length. Namely,
$$R M_1 = M_2 \Leftrightarrow R = M_2 M_1^{-1}
$$so if we let \(S\) be the sum of the diagonal components (trace) of \(M_2 M_1^{-1}\), then the angle \(\theta\) between the two rotation matrices \(M_1,M_2\) is
$$\theta = \arccos \frac{S-1}{2}
$$

Uniformly Distributed Random Vectors on a Sphere

 Using uniform random numbers \(\alpha,\beta\) in the range [0,1], a vector \(V\) that exists with equal probability on the surface of a unit sphere can be expressed as
$$V=\begin{pmatrix}
2 \beta -1 \\
2 \sin (2\pi\alpha) \sqrt{\beta(1-\beta)} \\
2 \cos (2\pi\alpha) \sqrt{\beta(1-\beta)}
\end{pmatrix}$$

Random Rotation Matrices

 Using uniform random numbers \(\alpha,\beta,\gamma\) in the range [0,1], a random rotation matrix \(M\) can be expressed as follows.
$$M=\begin{pmatrix}
\cos(2\pi\alpha) & \sin(2\pi\alpha) & 0\\
-\sin(2\pi\alpha) & \cos(2\pi\alpha)& 0\\
0&0&1
\end{pmatrix}
\begin{pmatrix}
1&0&0\\
0&2\beta-1&2\sqrt{\beta(1-\beta)}\\
0&-2\sqrt{\beta(1-\beta)}&2\beta-1
\end{pmatrix}
\begin{pmatrix}
\cos(2\pi\gamma)&\sin(2\pi\gamma)&0\\
-\sin(2\pi\gamma)&\cos(2\pi\gamma)&0\\
0&0&1
\end{pmatrix}$$

contents