Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 7

Quaternion Derivative from Angular Velocity

Recommended resources

Welcome back. In our previous lesson, we built the core operational machinery for our quaternion class, implementing multiplication, normalization, and the all-important vector rotation. Your math library can now represent and apply a static orientation. Today, we will bring that orientation to life by making it dynamic.

This lesson addresses a fundamental question in physics simulation: if an object has an angular velocity, how does its orientation change over time? We will derive and implement the crucial link between an angular velocity vector and the time derivative of its orientation quaternion. This provides the final mathematical tool required before we can start building and simulating full rigid bodies.

By the end of this lesson, you will be able to compute the time derivative of a quaternion from an angular velocity, which is the cornerstone of simulating rotational dynamics in your physics engine.

From Physics to Quaternions

Your background in classical mechanics will serve you well here. You know that for a point on a rigid body rotating with angular velocity , its linear velocity is given by the cross product:

Our goal is to find an equivalent relationship in the language of quaternions. If we represent the orientation of the body by a quaternion , any point in the body's local space can be transformed to world space by . Since the body is rigid, is constant. The change in the world-space position of the point is due entirely to the change in orientation, . Therefore, we need to find an expression for , the time derivative of the quaternion, that is equivalent to the physical law of angular velocity.


The Quaternion Kinematic Equation

Deriving this relationship from first principles provides a solid understanding of where the final formula comes from. It involves applying the product rule for derivatives to the quaternion rotation formula and relating the result back to the cross product definition of angular velocity.

The following article provides a clear, formal derivation. It's mathematically dense, but the result is a clean and powerful equation.

How to Integrate Quaternions · Ashwin Narayan

This article provides a formal derivation of the relationship between angular velocity and the time derivative of a quaternion, which is the mathematical foundation for all rotational dynamics.

Start at the beginning, in the section Integrating Angular Velocity, which frames the problem by connecting it to the physical definition. Then, carefully follow the derivation in the subsection The Differential Equation. The key steps involve relating the time derivative of a rotated vector to the angular velocity, and then using properties of quaternion algebra to isolate \dot{q}. The final result is the crucial kinematic equation. You can skip the part on the "Quaternion Exponential" for now; we'll touch on that concept later.

As the derivation shows, the relationship between the time derivative of the orientation quaternion, , and the angular velocity, , is given by:

In this equation:

  • is the time derivative of the orientation quaternion.
  • is the current orientation quaternion.
  • is the angular velocity vector represented as a pure quaternion, . This is a critical detail for implementation. The comment by the author in the article you just read confirms this representation.

This equation is known as the quaternion kinematic equation.


World Frame vs. Body Frame

An important subtlety is the frame of reference in which the angular velocity is expressed. The order of multiplication in the kinematic equation changes depending on the frame.

  1. World-Frame Angular Velocity (): If the angular velocity is defined in the global, fixed coordinate system, the equation is what we just saw:

  2. Body-Frame Angular Velocity (): If the angular velocity is defined in the object's own local, rotating coordinate system (as would be measured by an on-board gyroscope), the quaternion multiplication is reversed:

In a physics engine, it is common to store angular velocity in the body frame because the inertia tensor, which relates torque to angular acceleration, is constant in the body frame. For now, we will focus on the world-frame version for simplicity, but it's good to be aware of this distinction. You can always convert between them using .


From a Continuous Derivative to a Discrete Update

The kinematic equation gives us a continuous derivative, but our physics engine operates in discrete time steps (). To update the orientation in our simulation loop, we need to integrate this derivative. The simplest method is Forward Euler integration:

Substituting our kinematic equation into the Euler formula gives us a practical update rule:

This shows that the formula you might see in physics engine textbooks is simply a first-order Euler integration of the underlying quaternion differential equation.

physics engine - Applying angular velocity to quaternion - Game Development Stack Exchange

This Stack Exchange answer provides a more intuitive derivation and clearly shows how the continuous differential equation is turned into a discrete update rule suitable for a game loop.

Focus on the top-voted answer by user DarthRubik. Read the section from where the derivative is taken to the end of the post. This shows how we arrive at the equation for \dot{q} and then discretizes it using an approximation for a small time step \Delta t, resulting in the simple update formula you will implement.


Implementation and a Critical Caveat

When you integrate the rigid body state in a future module, you will implement this update. The process for a single time step dt will be:

  1. Retrieve the body's current orientation q and its world-frame angular velocity vector w_vec.
  2. Create a pure quaternion from the angular velocity: w_q = quaternion(0, w_vec.x, w_vec.y, w_vec.z).
  3. Calculate the quaternion derivative: q_dot = 0.5f * w_q * q.
  4. Update the orientation using Euler's method: q_new = q + q_dot * dt.
  5. Normalize q_new!

This last step is absolutely essential. The Euler integration is an approximation. Each time you apply it, small floating-point inaccuracies will cause the resulting quaternion to drift slightly from unit length. Over time, this accumulated error would cause your rotating objects to visibly distort (scale up or down). By re-normalizing the quaternion after every integration step, you enforce the pure-rotation constraint and keep the simulation stable.

How to Use Quaternions

This is a quick, practical summary of the integration formula and its caveats.

Watch the segment from that discusses the formula for updating orientation from angular velocities. Pay close attention to the two warnings the presenter gives: this is a first-order approximation, and the result must be normalized. This reinforces the practical considerations for your implementation.

As a visual example, the plot below shows how applying an angular velocity results in a smooth evolution of the four quaternion components over time. Your integration scheme will be calculating this evolution step-by-step.

This figure shows how the components of an angular velocity vector (left) and the corresponding orientation quaternion (right) might evolve over a short time interval. As angular velocity `ω` changes, the quaternion components `q_i` update according to the differential equation we've discussed, producing complex rotational motion.

Conclusion

You have now bridged the gap between the kinematic concept of angular velocity and the algebraic representation of orientation. This connection is the engine that will drive all rotational motion in your simulation.

Key Takeaways:

  • The rate of change of an orientation quaternion, , is governed by the kinematic equation (for world-frame angular velocity ).
  • For the calculation, the angular velocity vector must be represented as a pure quaternion .
  • In a discrete simulation loop, this continuous equation is integrated over a time step . A simple Euler step is .
  • After each integration step, the new orientation quaternion must be re-normalized to prevent numerical drift and maintain simulation stability.

We have now assembled a complete and powerful toolkit for handling 3D rotations. But why did we choose this path over the seemingly simpler Euler angles? In the next lesson, we will explore the critical problem of gimbal lock, which will provide a definitive answer and solidify the rationale for using quaternions in any robust 3D physics or graphics system.