This time I'm gonna go through a process of extracting rotation axis and angle from the rotation matrix . Lets recap some properties of the rotation matrix that we will be using.
- Is a square matrix.
- Is normalized, column and row vectors have unit length.
- Is orthogonal, column vectors are mutually orthogonal to each other. The same holds good for rows. In other words the dot product of any two pairs of row or column vectors is 0
- For orthogonal matrix holds that
- or for reflection.
To find the axis and angle of rotation we will call eigenvectors and eigenvalues for help. The eigenvalues of an orthogonal rotation matrix must satisfy one of the following:
- All eigenvalues are 1.
- One eigenvalue is 1 and the other two are . This corresponds to rotation angle
- One eigenvalue is 1 and the other two are complex conjugates of the form and
- The rotation axis is the eigenvector corresponding to the eigenvalue 1
Angle of rotation from eigenvalues
As long as the matrix is orthogonal which is true for our rotation matrix the trace (sum of the diagonal elements) is independent of the coordinate system used. In other words the trace is independent of the axis of rotation, it depends only on the rotation angle. We also know the sum of eigenvalues equals to the trace of the matrix.
so the rotation angle is
Angle of rotation from Rodrigues' formula
We can also derive this equation from the Rodrigues' formula. By doing so we will also prove that the eigenvalues of the rotation matrix are .
As we said before the trace is independent of the axis of rotation, it depends only on the rotation angle. Lets do the trace of both sides of this equation.
The trace of and the trace of any skew symmetric matrix is zero We also substitute The reason for that is that the which helps us during the simplification.
Earlier we saw that sum of the eigenvalues is
From the Rodrigues' formula we proved that
And again we get the same equation for the rotation angle
From the above we also proved that the sum of eigenvalues equals to
There is one issue here. If you invert the rotation axis and negate the rotation angle you get the same rotation. This means you can get two possible angle/axis pairs corresponding to the same rotation.
There are several ways we can find the rotation axis. Perhaps the easiest to understand is the following.
When we multiply the rotation matrix by a vector which is aligned with the rotation axis of the matrix the product will be the same vector. This vector will not move or get scaled. Let label this vector
By moving things around we get
Let's define new matrix We can see that when the matrix B gets multiplied by the vector the product is 0.
We say the vector belongs to the nullspace of the matrix B or it is a kernel of the matrix B. If B is invertible the only solution would be (trivial solution) which is not what we want. The matrix B is a result of where R is orthogonal matrix with determinant=1 which makes the B matrix singular -> determinant of B is zero. In this case we can find the solution as such This is called non trivial solution and it is our axis of rotation.
If the singular matrix has at least two linearly independent rows, then the vector in the nullspace of B is a cross product of these rows. In other words the cross product of two vectors in always lies in the nullspace of the matrix with the vectors as rows. Why is that? Lets look inside the multiplication of the matrix and the vector
If is a th row of B then the dot product of each row with the vector must be zero.
This means that the vector must be orthogonal to each row in the matrix . Our Matrix B is singular thus at least one vector is linearly dependent. Indeed each row vector in our matrix is a linear combination of the other two. In fact all row vectors lie in a plane. It should not be a surprise that this holds good for the columns as well since we started with an orthogonal matrix.
We said that the vector must be an orthogonal to each row vector of the B to satisfy Now, this is quiet easy to find since all row vectors lie in the plane so we just need to find a perpendicular vector to that plane. To do that we take a cross product of two rows, for example the first two and then normalize it.
and normalize it
The is our normalized axis of rotation.
What we have just done was in essence extraction of eigenvector belonging to the eigenvalue = 1. As we said the axis of rotation has this property
On first looks you can see that the vector is an eigenvector with a corresponding eigenvalue .
Using Cayley transformation
To get the axis of rotation we can use the Cayley formula
Where is a skew symmetric matrix representing the axis of rotation with components We can also go back to the rotation matrix
The matrix is scaled by which we can use to normalize the axis.
Rotation axis from Rodrigues' formula
Other option is to use this relation
Since is skew symmetric then This rule helps us to simplify the following
We also know that the outer product is
Using these substitutions we get
Since is symmetric then
And to get the normalized axis of rotation
From this we can see the axis of rotation is actually only with length
If we don't know we can use the length to normalize the axis vector.
Now we need to convert the skew symmetric matrix back to the vector representation . We know
so the is