Finding Axes and Angles of Rotation from 3D Rotation Matrix
Any given 3D Rotation Matrix can be converted to A Pair of Axis Vectors and Corresponding Rotation Angles around those Axis Vectors.
If one of the Axis Vector is Vector \(\vec{A}\) with Counter Clockwize Rotation Angle \(\phi\), the other Axis Vector is Vector \(-\vec{A}\) with Counter Clockwize Rotation Angle \(2\pi - \phi\) (where \(0 \leq \phi < 2\pi\)).
The formula for General 3D Rotation Matrix \(R\) is given as
where \(c = \cos \phi, s = \sin \phi, t = 1-\cos \phi\), \(\phi\) is the Angle of Rotation and \(X\), \(Y\) and \(Z\) are the Components of Unit Vector representing the Axis Vector of Rotation.
The following gives the steps / pseudocode for Finding Axes and Angles from Rotation Matrix as given in equation (1) above
If \(\cos \phi=1\) then \(\phi=0\). This makes \(t=0\) and \(\sin\phi=0\). Under such circumstances the Rotation Matrix is an
Identity Matrix and Any Arbitraty Vector can be given as the Axis.
If \(\cos \phi=-1\) then \(\phi=\pi=180^\circ\). This makes \(t=2\) and \(\sin\phi=0\). To find the Axis, find \(X^2\),
\(Y^2\), \(Z^2\) as follows
If \(X^2 \neq 0\) then find the 2 values of \(X\). For each value of \(X\) find the values of \(Y\) and \(Z\) as follows
\(Y={\Large \frac{R[0][1]}{2X}}\)
\(Z={\Large \frac{R[0][2]}{2X}}\)
If \(X^2 = 0\) but \(Y^2 \neq 0\) then find the 2 values of \(Y\). For each value of \(Y\) find the values of \(X\) and \(Z\) as follows
\(X={\Large \frac{R[1][0]}{2Y}}\)
\(Z={\Large \frac{R[1][2]}{2Y}}\)
If \(X^2 = 0\) and \(Y^2 = 0\) but \(Z^2 \neq 0\) then find the 2 values of \(Z\). For each value of \(Z\) find the values of \(X\) and \(Y\) as follows
\(X={\Large \frac{R[2][0]}{2Z}}\)
\(Y={\Large \frac{R[2][1]}{2Z}}\)
The 2 Sets of \(X\), \(Y\) and \(Z\) values thus obtained give the Components of the 2 Unit Vectors for the 2 Axes of Rotation. Both the Unit Vectors are
in Opposite Direction to each other.
If \(\cos \phi\neq 1\) and \(\cos \phi\neq -1\) then calculate the value of \(t=1-\cos\phi\). To find the Axes and Angles of Rotation, find \(X^2\),
\(Y^2\), \(Z^2\) as follows
If \(X^2 = 0\) but \(Y^2 \neq 0\) then find the 2 values of \(Y\). For each value of \(Y\) find the values of \(\sin \phi\), \(\phi\), \(X\) and \(Z\) as follows
If \(X^2 = 0\) and \(Y^2 = 0\) but \(Z^2 \neq 0\) then find the 2 values of \(Z\). For each value of \(Z\) find the values of \(\sin \phi\), \(\phi\), \(X\) and \(Y\) as follows
The 2 Sets of \(X\), \(Y\) \(Z\) and \(\phi\), values thus obtained give the Components of the 2 Unit Vectors for the 2 Axes of Rotation and the Corresponding Angles of Rotation. Both the Unit Vectors are
in Opposite Direction to each other. If one of the Angles Values obtained is \(\theta\) the other is \(2\pi - \theta\).
The \(m\_arctan2\) is the Modified Arctangent Function, which calculates the angle \(\phi\) such that \(0 \leq \phi < 2\pi\).