- What’s there?
- Rotations as linear transformations
- Pre- and Post-Multiplication: The Duality of Coordinate Frames
- Gimbal Lock
- Quaternions
- Sources
What’s there?
I want to try and cover every other kinda trivial / small things related to matrices / LinAlg in this. This covers
- Affine spaces (Other important matrix bits)
- Inner products of functions (Other important matrix bits)
- Orthogonal projections (Other important matrix bits)
- Matrix approximation (Other important matrix bits)
- Rotations and quaternions (This post!)
Why do I write this?
I wanted to create an authoritative document I could refer to for later. Thought that I might as well make it public (build in public, serve society and that sort of stuff).
Rotations as linear transformations
As always, basics!
Isometry
The defining characteristic of a rigid body motion is that it preserves the distances between all points on the body.
A transformation that preserves distances is called an isometry.
In a vector space equipped with an inner product (and its induced norm), this means a transformation
must preserve the norm of vectors and the angles between them. This is mathematically equivalent to preserving the inner product:
Orthogonal Matrices preserve norms
For any linear transformation represented by a matrix , the inner product preservation property is
. This expands to
.
This implies the defining property of an orthogonal matrix:
This means the inverse of an orthogonal matrix is its transpose, .
There you go, said it in a roundabout way since I’ve spoken about this atleast twice now:)
Distinguishing Rotations from Reflections
Orthogonal matrices represent all isometries that fix the origin.
This is a set which includes both rotations and reflections.
The determinant of an orthogonal matrix is always .
A transformation is said to preserve orientation (or “handedness”) if its determinant is positive.
A pure rotation is an orientation-preserving isometry. Therefore, a rotation is represented by an orthogonal matrix with a determinant of +1.
Special Orthogonal Group SO(n)
The set of all
rotation matrices forms a mathematical group under matrix multiplication. This group is known as the Special Orthogonal Group, denoted
.
E.g.,
represents rotations in the plane, and
represents rotations in 3D space.
Rotations in 2D and 3D
Rotations in 2D,
: The action of a 2D rotation on the standard basis vectors
completely defines the transformation. A counter-clockwise rotation by an angle
maps
and
. The columns of the rotation matrix are these transformed basis vectors, yielding:
Rotations in 3D can also be derived to be
![]()
Pre- and Post-Multiplication: The Duality of Coordinate Frames
This is actually a very important concept!
The non-commutativity of matrix multiplication () is not a mathematical inconvenience; it is the essential property that allows matrices to capture the non-commutative nature of 3D rotations. The choice of whether to pre-multiply (
) or post-multiply (
) depends entirely on the coordinate frame in which the new rotation is defined!
Foundations
Coordinate Frames
A coordinate frame, which we denote , is a coordinate system used to represent the position and orientation of objects. In
, it consists of an origin point and a set of
orthonormal basis vectors.
A vector’s components are only meaningful with respect to a specific frame.
We denote a vector expressed in frame
as
.
Active vs. Passive Transformations
A rotation matrix can be interpreted in two ways –
- Active Rotation: The coordinate system is fixed, and the object (represented by a vector) is rotated.
The matrix transforms the vector’s coordinates to new coordinates within the same frame. This is the more common interpretation.
- Passive Rotation: The object is fixed in space, and the coordinate system is rotated.
The matrix transforms the vector’s coordinates from the old frame to the new frame. This is a change of basis.
A rotation of the frame bymeans the coordinates of a fixed vector in the new frame are given by
times the old coordinates.
The choice between pre- and post-multiplication arises when we compose multiple rotations. This is best understood by considering two primary scenarios: rotations defined with respect to a fixed, global frame versus rotations defined with respect to a moving, local frame.
Scenario A: Pre-Multiplication (Rotations in a Fixed Global Frame)
This is the case where all rotations are defined with respect to the same, unchanging, external coordinate system.
This is called the world frame or global frame, which we will denote as
.
Here, for two successive rotations, we write:
The new rotation matrix, , is pre-multiplied (multiplied on the left) to the existing rotation matrix,
. The order of matrix multiplication (
then
) is the same as the order of application to the vector (first
, then
).
Scenario B: Post-Multiplication (Rotations Relative to a Moving Local Frame)
This is the case where a sequence of rotations is defined with respect to the object’s own, changing coordinate system.
This is often called the body frame or local frame, which we will denote as
.
- The Transformation: An object initially has an orientation described by the matrix
, which represents the orientation of its local frame
with respect to the global frame
. Let’s denote this as
.
- Composition: Now, we want to apply a second rotation,
, but this rotation is defined relative to the object’s current, rotated frame,
. This local rotation transforms frame
to a new frame
, and is denoted
. We want to find the final orientation of the object,
, in the global frame.
- The Rule: To find the final orientation, we chain the transformations. The orientation of the new frame
relative to the global frame
is the orientation of
in
followed by the orientation of
in
. This corresponds to a matrix product:
If we let
and
, the final orientation is:
The new rotation matrix, , is post-multiplied (multiplied on the right) to the existing rotation matrix,
.
How do you determine the choice?
The choice between these two conventions is not arbitrary; it is dictated by the problem’s physical or conceptual setup.
| Convention | Pre-multiplication: | Post-multiplication: |
|---|---|---|
| Interpretation | Rotations are applied with respect to a fixed, external (world) coordinate system. | Rotations are applied with respect to the object’s own, moving (body) coordinate system. |
| Analogy | An air traffic controller describing an airplane’s orientation relative to the ground. “First turn 90 degrees North, then pitch up 20 degrees.” | A pilot inside the cockpit describing their maneuvers. “First I will pitch up 20 degrees, then I will yaw 10 degrees to my right.” |
Application: Kinematic Chains
A robot arm is a chain of links, where each link’s frame is attached to the previous one. The orientation of link 2 is defined relative to link 1. The orientation of link 3 is defined relative to link 2, and so on. The orientation of the end-effector (frame ) with respect to the base (frame
) is the post-multiplication of the successive joint rotations:
Gimbal Lock
Getting back to , any arbitrary rotation is is a sequence of three rotations about principal axes, known as Euler angles (e.g., yaw, pitch, roll).
This suffers from a singularity where two of the three rotational axes align, causing the loss of one degree of freedom. This is called the Gimbal lock.
At this point, it is impossible to perform small rotations about one of the original axes, leading to instability in control and animation systems.
I really cannot explain it better mathematically than this StackExchange Answer and this YT video for a demo.
How do you solve this? Quaternions.
Quaternions
Hierarchy of number systems
- Real Numbers (
): Ordered, commutative, associative. Lacks algebraic closure (e.g.,
has no real solution).
- Complex Numbers (
): Adds the imaginary unit
where
. The system is algebraically closed, commutative, and associative. It sacrifices the property of being an ordered field.
- Quaternions (
): Adds two more imaginary units,
and
. The system is associative but sacrifices the property of commutativity in multiplication (
). This non-commutativity is not a flaw; it is the essential feature that allows quaternions to model non-commutative 3D rotations.
- Octonions (
): Adds four more units. The system is neither commutative nor associative, sacrificing associativity in multiplication (
).
Quaternion Algebra
A quaternion
is an element of the form:
where
are real numbers, and
form a basis for this 4D vector space.
is the scalar part, denoted
.
is the vector part, denoted
. A quaternion with a zero scalar part is called a pure quaternion.
The algebra is defined by the Hamiltonian rules for the basis elements:
This single, compact relation generates the entire non-commutative multiplication table:
The multiplication of two general quaternions
and
is defined by distributing terms and applying these rules. This leads to a more compact formula relating quaternion multiplication to the vector dot and cross products:
Quaternion Operations
- Conjugate:
. The conjugate of a product is the reversed product of the conjugates:
.
- Norm: The norm of a quaternion,
, is a non-negative real number defined as:
This is the standard Euclidean norm in
. The norm is multiplicative:
.
- Inverse: The multiplicative inverse of a non-zero quaternion
is:
This ensures that
is a division algebra: every non-zero element has an inverse.
- Unit Quaternion: A quaternion with a norm of 1,
. For unit quaternions, the inverse is simply the conjugate:
. The set of all unit quaternions forms a 3-dimensional sphere (
) embedded in
.
Geometry of 3D Rotations
Representing Rotations with Unit Quaternions
A rotation in is uniquely defined by an axis of rotation (a unit vector
) and a right-handed angle of rotation
.
Euler’s Rotation Theorem states that any composition of rotations is equivalent to a single rotation about some axis.
I mean, this makes sense intuitive as well right? Not gonna prove it.
A unit quaternion
represents such a rotation via the Euler-Rodrigues formula:
Notice the use of the half-angle $\theta/2$. This implies that
- A rotation of
about any axis corresponds to
, and
- A rotation of
is required to return to the identity quaternion
.
This mathematical structure is known as a double cover: the group of unit quaternions (denoted
or
) is a double cover of the group of 3D rotations
.
The two quaternions
and
correspond to the exact same physical rotation in 3D space.
The Sandwich Product
- Embed: Lift the vector
into the quaternion algebra by representing it as a pure quaternion
:
- Transform: Apply the rotation via the sandwich product:
- Project: The result
is guaranteed to be another pure quaternion. The vector part of
is the rotated vector
.
Composition of Rotations
If a rotation represented by
is followed by a rotation represented by
, the single composite rotation is represented by the quaternion product:
The non-commutativity of quaternion multiplication (
) correctly reflects the non-commutativity of 3D rotations (e.g., rotating 90 degrees about the x-axis then the y-axis is different from the reverse).
This is a significant advantage over Euler angles, where composition is complex and unintuitive.
Spherical Linear Interpolation (SLERP)
To smoothly interpolate between two orientations represented by unit quaternions
and
, we need to find a path of constant rotational velocity on the surface of the
hypersphere.
This path is a great-circle arc.
What this means that it’s a circle arc in 4 dimensions. We use SLERP for this.
where
is the interpolation parameter and
is the angle between the four-dimensional vectors corresponding to
and
, given by
.
This formula produces smooth, constant-velocity rotations, a feat that is notoriously difficult and unstable with Euler angles.
Applications
Duh, you rotate everywhere in robotics.
Sources
- Mathematics for Machine Learning (link)
Leave a comment