Quaternion Lab: i, j, k Half-Turns, Rotations, SLERP and Spinors
A free interactive quaternion lab: multiply i, j and k and watch each one turn a 3D hand half a turn, see why i² = −1 after a full 360° turn, compare SLERP with Euler-angle blending on a robot arm (gimbal lock included), convert between axis-angle, quaternions, rotation matrices and Euler angles, and see the 720° spinor turn.
Each of i, j and k is a half-turn (180°) about the x, y or z axis. Press the buttons to multiply them, one after another, and watch the hand turn. The hand only shows the rotation; the quaternion also carries a sign, ±1, that the hand cannot show: i·i is a full 360° turn, the hand looks exactly as it started, yet i² = −1. Drag the picture to look around it.
Hamilton's table
Row times column. The last product is highlighted.
Order matters: i·j = k but j·i = −k. Both turn the hand to the same place (a half-turn about z), only the hidden sign differs.
A robot arm has to move its gripper from pose A to pose B: both the place and the way the gripper is turned. Robots, drones, spacecraft and game engines store that turn as a quaternion and blend between the two with SLERP (spherical linear interpolation): one steady turn about one fixed axis, the shortest way. The orange ghost shows what happens if you blend the three Euler angles (yaw, pitch, roll) one by one instead: it wobbles, can go the long way round, and near pitch 90° (gimbal lock) it spins wildly. Drag to look around.
Pose A (yaw, pitch, roll)
Pose B (yaw, pitch, roll)
\(\displaystyle \Delta q = q_1\,q_0^{-1} = \cos\tfrac{\varphi}{2} + \mathbf{n}\,\sin\tfrac{\varphi}{2},\qquad q(u) = (\Delta q)^{u}\,q_0\)
Type a rotation in any form and the others follow: axis and angle, quaternion, rotation matrix or Euler angles in any of the six orders. Below it, multiply two quaternions and turn a vector with q v q*. The picture shows the turn, its axis (dashed) and your vector.
Axis and angle
The axis does not need to be a unit vector; it is scaled for you. Angles over 360° are kept: that is where the sign of q changes.
Quaternion q = w + xi + yj + zk
Rotation matrix
Edit a cell and the closest rotation is used. Columns are where the x, y and z axes end up.
Euler angles
Quaternion arithmetic
Turn a vector: v′ = q v q*
The vector becomes a "pure" quaternion (no real part), is sandwiched between q and its conjugate, and comes out pure again. Using −q instead of q gives exactly the same v′: the two minus signs cancel.
Turn the hand round and round about one axis. Its rotation matrix repeats every 360°, but its quaternion w = cos(θ/2) only repeats every 720°: after one turn q = −1. A ribbon tied from the wall to the hand shows the same thing: after one turn its twist cannot be undone by moving the ribbon around (without turning the hand), after two turns it can (Dirac's belt trick). Drag to look around.
More on spin-½: the Spin & Angular Momentum Simulator (the 1975 neutron experiments that saw the 720° turn) and Spin-½ explained.
How the Quaternion Lab works
Everything is worked out in your browser with plain quaternion algebra; nothing is uploaded. A quaternion is four numbers, q = w + xi + yj + zk, with Hamilton's rule i² = j² = k² = ijk = −1 (1843, carved on Broom Bridge in Dublin). A unit quaternion is a turn: turning by θ about the unit axis n is q = cos(θ/2) + n sin(θ/2), and it turns a vector v by v′ = q v q*. Because of the half angle, q and −q are the same turn, and a turn of 360° gives q = −1.
i, j and k as half-turns
Put θ = 180° in the formula above and the cosine vanishes: the half-turn about x is exactly i, about y is j, about z is k. Multiplying on the right means "then turn about the hand's own (body) axis", which is how a robot wrist or an aircraft's controls work; ticking "the room's axes" multiplies on the left instead. Either way i·j lands on the same place as a half-turn about z, and i·i = −1 lands where it started. The hand cannot tell +1 from −1; the dial can.
Why SLERP beats Euler angles
Euler angles describe a turn as three turns about fixed-order axes. Blending each of the three numbers separately gives a path whose speed changes along the way and which can take the long way round (yaw 170° to −170° sweeps 340° instead of 20°). When the middle angle reaches ±90° the first and third axes line up and one degree of freedom is lost: gimbal lock, the problem that nearly hurt Apollo 13's guidance platform. SLERP works on the unit sphere of quaternions, where every orientation is one point, and walks the great circle between the two: one fixed axis, constant angular speed, the shortest turn. The robot arm here is drawn with simple inverse kinematics (a turning base, shoulder and elbow to place the wrist, then a roll-pitch-roll wrist to turn the gripper); the wrist readout shows when the wrist itself nears its own singularity.
720° and spinors
The quaternions of length 1 form the group SU(2), which covers the rotation group SO(3) twice: every turn has two quaternions, q and −q. Follow a turn continuously from 0° and you reach −1 at 360° and come back to +1 only at 720°. Spin-½ particles (electrons, neutrons) carry exactly this sign: in 1975 two groups turned neutrons by a magnetic field and saw their interference come back only after 720° (see the Spin Simulator). The ribbon picture is the belt trick: tie a belt to a book, turn the book once and the belt's twist cannot be removed without turning the book back; turn it twice and you can pass the belt around the book until it is flat. The ribbon drawn here is the shortest path in SU(2) from 1 to q, which is the least twist the ribbon can be relaxed to; it is a picture of the mathematics, not a simulation of a real belt. Chantal Roth's elastic-medium model of spin, which inspired this page, is one proposed mechanical picture of why particles behave like this: a hypothesis, not established physics. The 720° property itself is established.
Questions
- Why is the angle halved in the quaternion?
- Because q appears twice in v′ = q v q*. Each copy turns v by θ/2 and together they turn it by θ.
- Which Euler order should I use?
- Aircraft, ships and most robot arms use ZYX (yaw, pitch, roll). Here "XYZ" means R = Rx · Ry · Rz: turn about x, then about the new y, then about the new z (the same as turning about the fixed z, y, x). The calculator lists all six Tait-Bryan orders.
- Are q and −q different?
- As rotations, no: they turn every vector the same way. As quaternions, yes, and the difference matters for spin-½ and when blending: SLERP flips one of them so it takes the short way round.
- What is gimbal lock?
- The point where the middle Euler angle is ±90°, so the first and last axes line up and only their sum or difference matters. The orientation is fine; the three numbers just stop describing it uniquely. Quaternions have no such point.
- Is the matrix calculator exact?
- It uses double-precision floating point (about 15 digits) and Shepperd's method to turn a matrix into a quaternion, which stays accurate near 180° turns.
Further
- Chantal Roth, What Is Spin-1/2, Really? A Mechanical Model (Red Pill channel) and her Mechanical Universe simulation library; demos i, j, k half-turns and quaternions at work.
- W. R. Hamilton (1844). On quaternions; or on a new system of imaginaries in algebra. Philosophical Magazine 25, 10-13.
- K. Shoemake (1985). Animating rotation with quaternion curves. SIGGRAPH '85, 245-254 (the SLERP paper).
- S. W. Shepperd (1978). Quaternion from rotation matrix. Journal of Guidance and Control 1, 223-224.
- H. Rauch et al. (1975), S. A. Werner et al. (1975): the neutron 4π experiments, Physics Letters A 54, 425 and Physical Review Letters 35, 1053.
Related: Spin & Angular Momentum Simulator · Spin-½ · Matrix Calculator · 3D Graphing Calculator · Trigonometry · More MES tools
