Equations of Motion with Quaternions
Apr 17, 2025 — 5 min readThis post is mainly intended as a reference for my future self. For everyone else, this is yet another post with slightly different symbols in the equations of motion.
Every time I work on a project involving equations of motion, I find myself searching through my old notes and browsing the internet. Instead of collecting the pieces again and again, I will do it one last time here.
Rigid Body Dynamics
Inertia Matrix
A rigid body has a mass
The inertia matrix is symmetric, so
State Vector
To describe the full state of a rigid body, we need to know its linear velocity, angular velocity, orientation, and position.
The velocity is defined in the body-frame. This will come in handy later. The velocity vector is:
where
The angular velocity is defined in the body-frame as well:
where
The orientation of the body relative to the inertial frame is defined by a quaternion:
where
Position is defined in a local north-east-down (NED) frame. This describes the position of the center of mass in the local reference frame. The position vector is:
While
If we put everything together, we get one big state vector:
For the equations of motion, we need to find the derivative of the state vector.
Linear Acceleration
For the velocity derivative, the equation for the acceleration in body frame is:
where
Angular Acceleration
The angular velocity derivative is:
where
Quaternion Derivative
The derivative of the quaternion is:
where that fancy symbol
where
Position Derivative
The position derivative is just the velocity, but in the inertial frame:
Since the velocity is defined in the body frame, we need to rotate that velocity vector
where
State Derivative
Now we can put everything together. The state derivative is:
Propagating state with Runge-Kutta
We can use the Runge-Kutta method to calculate the state at a next time step. It's a numerical approximation of the integral of the differential equations.
where
Roll, pitch, yaw angles
Quaternions are nice in the differential equations, but for inputs and outputs we prefer Euler angles. For the initial state, we can get the quaternion for a given roll, pitch, and yaw angle:
where
To obtain the roll, pitch and yaw angles from the quaternion:
And now what?
These equations are pretty cool and easily implemented in code. Next, you can start applying forces and moments to the rigid body and see what happens. For example, you can apply aerodynamic forces and moments to simulate the behavior of a multi-rotor or fixed-wing UAV.