Quaternions and Change of Basis
Expressing the same rotation in a different coordinate frame using quaternions.
Introduction
In this post, I want to talk about expressing the same rotation in a different coordinate frame. To get to that I first want to talk about linear algebra and how we express vectors in different coordinate frames first.
By the end of this article we will see that
where and represent the same rotation expressed in to different coordinate frames, and is a quaternion describing the rotational relationship between those frames.
Which looks awfully similar to the change of basis formula for a linear transformation. So let’s take a quick look at that first.
Changing a vector’s basis
Let’s say we have a vector, , to keep things simple, let’s assume it is expressed in the standard basis, .
Suppose we have two other bases, and , which are and respectively. Notice that:
Where and are the coordinates of the vector in the respective bases. If we want to express the vector in basis given , we can do the following:
Multiplying both sides by from the left we get:
which is the change of basis formula. The matrix is called the change of basis matrix from basis to basis .
Changing a rotation’s basis
We can actually generalize the same idea to linear transformations. Let’s say we have a linear transformation that is represented by matrix in basis and by matrix in basis . Let’s track back a bit first, we know:
If we have , which is a vector expressed in the standard basis, we can express it in basis as follows:
and since
We now have:
This is true for any vector , so we can say that the matrix representing the linear transformation in basis is:
Similarly:
Now if we substitute from the first equation into the second we get:
Let , which is the change of basis matrix from basis to basis . Then we can rewrite the above equation as:
So there we go, we now have the change of basis formula for a linear transformation. We now that a rotation in is a linear transformation and its matrix follows the same rule.
A 3D rotation can also be represented by a unit quaternions, so one expects that changing the coordinate frame of a rotation should have an equivalent operation with quaternions. We will now see the matrix similarity transformation corresponds to conjugation by the quaternion describing the relationship between the two coordinate frames.
Expressing a rotation in a different coordinate frame using quaternions
Alright, let’s say we again have a vector , and let be a rotation matrix and let be the unit quaternion representing that rotation. We know that:
On the right side of the equality, we treat v as a pure quaternion. Since q is a unit quaternion, let’s say is the rotation matrix corresponding to the quaternion . Then we have:
Now let’s consider the change of basis formula for the rotation matrix again
If we assume frames and are both right handed and also orthonormal, then is a rotation matrix and can be represented by a unit quaternion . Then we have:
If we have quaternions and then means first rotate by and then rotate by . If and are the rotation matrices corresponding to the quaternions, then we have:
Since rotating by and then by is the same as rotating by . So we can rewrite the change of basis formula as:
And then finally:
Final thoughts
I was trying to make a configurable joint follow a bone transformation in unity and realized to use the configurable joint’s target rotation set method properly i had to express the same rotation in a different coordinate frame and I thought it could be nice to have this in writing both for myself and for anyone who might want to do the same in the future for whatever reason.
There definitely are some “trust me bro” parts in this article like where i stated each unit quaternion corresponds to a rotation matrix, but I think it is a good enough reference for anyone who wants to understand how to express the same rotation in a different coordinate frame using quaternions.
You can reach out to me on my mail or linkedin if you have any questions or comments. Thanks for reading!