Quaternions, finally clear.
Four numbers that describe any 3D orientation, with no gimbal lock. Here you don't just read the formulas: you turn the object, move the sliders and watch every number change.
No sign-up · works in the browser · C code included
Three parts, from "why" to working C code
AWhy quaternions, and what they are
We see where Euler angles break, look at rotations as one turn about one axis, and meet the four numbers.
Why quaternions, and what they are
We see where Euler angles break, look at rotations as one turn about one axis, and meet the four numbers.
BWorking with quaternions
Multiply them, rotate vectors with them, chain rotations, and convert to matrices and Euler angles.
Working with quaternions
Multiply them, rotate vectors with them, chain rotations, and convert to matrices and Euler angles.
CQuaternions in practice
Update an orientation from its turn rate, blend two orientations smoothly, and write it all in C.
Quaternions in practice
Update an orientation from its turn rate, blend two orientations smoothly, and write it all in C.
Read a little, play with it, check yourself
- 1 · Read
One idea at a time
Short text in plain words, and only the formulas we really use in code.
- 2 · Play
Visuals, one idea at a time
Each lesson has several small visuals, one idea each, from the simplest case to the full picture. Turn the object, move the sliders, and see the four numbers react.
- 3 · Check
A few quick questions
Open the answer when you are ready. If it feels easy, you've got it.
For anyone who needs 3D rotations to make sense
Good fit
You make games, 3D graphics, animation, robots, drones or VR, or you study them. You have seen quaternion formulas and want to finally understand them, or you are meeting them for the first time.
What you need
School trigonometry and a browser. No library to install and no account.
Built on standard references
The formulas and conventions follow these texts. Each lesson lists the ones it uses, with the section to read if you want the full derivation.
- H. A. Hashim, "Special Orthogonal Group SO(3), Euler Angles, Angle-axis, Rodriguez Vector and Unit-Quaternion: Overview, Mapping and Challenges", 2019
- J. Diebel, "Representing Attitude: Euler Angles, Unit Quaternions, and Rotation Vectors", Stanford University, 2006
- J. Solà, "Quaternion kinematics for the error-state Kalman filter", 2017
- J. B. Kuipers, "Quaternions and Rotation Sequences", Princeton University Press, 1999
- G. Sanderson and B. Eater, "Visualizing quaternions: an explorable video series"
- G. Sanderson (3Blue1Brown), "Visualizing quaternions (4d numbers) with stereographic projection", 2018
- K. Shoemake, "Animating rotation with quaternion curves", SIGGRAPH 1985
Questions
How much math do I need?
School trigonometry: sin, cos and a right triangle. Vectors help, and lesson 3 shows the only bit of complex numbers we need. Everything else we build on the way, with pictures first.
Where are quaternions used?
Wherever something turns in 3D: game engines and animation, 3D graphics and cameras, robots and drones, spacecraft, phones and VR headsets.
Is it really free?
Yes. All 11 lessons are free to read, with no sign-up.
Which convention do you use?
Hamilton quaternions with w first, q = [w, x, y, z], and right-handed axes with x forward, y left and z up. Euler angles are in ZYX order (yaw, pitch, roll). Lesson 11 notes what to check if your engine or library does it differently.
Can I use the C code in my project?
Yes. Copy the two files into any C or C++ project. Lesson 11 shows how to test it first.
Does it work on my phone?
Yes. Drag with one finger to turn the 3D views. A bigger screen is nicer for the labs with two views side by side.