2d rotation
A 2d rotation has only one parameter , when the basis vectors and are rotated by an angle
Which builds the rotation matrix
When a vector is transformed by this matrix we know that the vector will be a linear combination of the basis which are and
Using a matrix to encode this operation
See also
complex numbers
3d rotation
About cardinal axes
See also
About an arbitrary axis
Given an axis and an amount of rotation around it our goal is to find a rotation matrix that rotates about by th angle
The basic idea is to solve this problem in a plane perpendicular to which becomes a 2d problem
Separate in two vectors, a vector parallel to called and a vector perpendicular to called such that
After the rotation it’s obvious that the component will be the same and only the vector will be rotated
A plane can be defined with two vectors that lie on it, since we have and we also know the normal of the plane (which is ) any vector perpendicular to both vectors will also lie in the plane, we can use the cross product to find this vector
The length of is
Which means that has the same length as , note that even though they have the same length they don’t necessarily have unit length
and form now a 2d coordinate space where the -axis is and the -axis is
Let be a vector that is the result of rotating by an angle , we can find the projection of it onto the -axis and the -axis as follows
- Expressing as a linear combination of the basis
Reconstructing the solution from the observations above
Finally
Now we can compute what the basis vectors are after the transformation above (by using each of the basis vectors as on ) to construct a rotation matrix
Constructing the matrix from these vectors
3d rotations using quaternions
A complex rotor is a unit norm complex number which rotates another complex number by the angle and has the form
Hamilton had hoped that a unit-norm quaternion could be used to rotate a vector which is stored as a pure quaternion , the unit norm quaternion is given by
Let’s compute the product
Special case
What if is perpendicular to ? Then the scalar quantity of is zero and we are left with the pure quaternion
Let’s analyze the vector part of (which is now a 3d entity because it’s a pure quaternion), since is perpendicular to then the vector will have a norm equal to and also since is a unit vector then which means that we have two orthogonal vectors with the same length
To rotate the vector about let’s transform to the 2d space whose basis vectors are and and perform the rotation there which is trivially , therefore all we have to do in is make the scalar quantities multiplying each vector equal the projection of the rotated vector over the basis
Which makes the quaternion have the form
And it acts as a rotor only when is perpendicular to
Important notes/facts about orthogonal quaternions
- If is a rotor about the unit vector by an angle whose vector term is perpendicular to the pure quaternion
- and rotate by an angle about
- and rotate by an angle about
- Each of these products leave unscaled (because is a unit norm quaternion)
General case
Let’s use as the starting point, note that this time its vector part it’s not necessarily perpendicular to the pure quaternion , the product yields
Note that the term does not vanish since for the general case and are no longer perpendicular, what’s more important is that the product is no longer a pure quaternion, multiplying a vector by a non-orthogonal quaternion has converted some of the vector information into the quaternion’s scalar component
What happens if we post-multiply by , could it reverse the operation? (Note that since is a norm quaternion )
Let’s first check if doing this multiplication makes the scalar component vanish
Indeed it magically made the scalar component vanish! Now let’s look at the vector component of
Let’s
expand the cross product
Therefore
Let’s make and just like in (it worked as a rotor when it was orthogonal to , it might work with the general case too)
Which involves double-angle terms, replacing these terms with
double angle-identities
The product created a pure quaternion equal to rotated by an angle , if we want to rotate by an angle we must build a half angle quaternion (note above that was equal to )
Using the product is
Note that the vector part of is identical to
Quaternion difference and dot product
Let and be two unit norm quaternions (rotors that have the same form as ), the quaternion to rotate from to is given by and is known as quaternion difference, finding the value of given that we know and
Expanding the product
Note that the scalar part of this quaternion is equal to the inner product (a generalization of the dot product to abstract vector spaces) between two quaternions
Remembering that a rotor is given by we can relate the inner product between rotor quaternions with the scalar quantity of and interpret it geometrically just like the dot product between two vectors in 3d/2d space but this time noticing that the dot product gives the cosine of half the angle between the quaternions
This means that the angle between and is equal to
Or using the
half angle formulas
The second formula works for all the cases as noted
here
(the first one doesn’t work when )