Here’s a collection of quaternion formulas. Quaternions are very useful for orientation sensing, game programming and augmented reality applications.
Axis Angle To Quaternion
Where the axis is v and the angle is theta
Quaternion To Axis Angle
Where theta is the angle and v is the axis vector
Quaternion From Angular Velocity
The first step is to convert angular velocity into an axis angle. w is angular velocity and t is the time period (sample rate of gyroscopes)
Using theta as the angle and v as the axis vector, it’s possible to translate this axis angle representation into a quaternion using the above formula.
Quaternion To Angular Velocity
To do this, translate the quaternion into an axis-angle. Again, v represents the axis, theta is the angle and t is the
Euler Angles To Quaternion
Euler angles are interesting because the order in which the angles are applied is important. The same angles applied in different orders won’t give you the same result. The most common order of application is heading, pitch then roll.
Euler angles are essentially three axis angles. Heading is a rotation around the z axis, pitch is an angle around the y axis and roll is around the x axis. It’s easy to convert these three axis angles into three quaternions, then multiply them together to create a single quaternion representation of the original euler angles.
Quaternion To Euler Angles
There’s an elegant solution to this problem.
To extract a heading euler angle from a quaternion
Pitch euler angle from quaternion
Roll euler angle from quaternion
To multiply quaternion q by quaternion r to produce quaternion s.
Quaternions can be used to translate vectors from one frame of reference to another.
q(x,y,z) is a vector constructed from the x,y,z components of the quaternion q. v is the vector to rotate and rv is the rotated vector.