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.

Inspired by Chantal Roth's Mechanical Universe simulations. Video: What Is Spin-1/2, Really? A Mechanical Model · her simulation library · demos: i, j, k half-turns and quaternions at work. The code and text here are our own.

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.

Turning speed:

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.

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.

Hamilton's rule \(\displaystyle i^2 = j^2 = k^2 = ijk = -1,\qquad ij = k = -ji,\quad jk = i = -kj,\quad ki = j = -ik\)
a turn as a quaternion \(\displaystyle q = \cos\tfrac{\theta}{2} + (n_x i + n_y j + n_z k)\sin\tfrac{\theta}{2},\qquad v' = q\,v\,q^{*}\)
the product \(\displaystyle q_1 q_2 = \big(w_1 w_2 - \mathbf{v}_1\!\cdot\!\mathbf{v}_2,\ \ w_1\mathbf{v}_2 + w_2\mathbf{v}_1 + \mathbf{v}_1\times\mathbf{v}_2\big)\)
quaternion to matrix \(\displaystyle R = \begin{pmatrix} 1-2(y^2+z^2) & 2(xy - wz) & 2(xz + wy)\\ 2(xy + wz) & 1-2(x^2+z^2) & 2(yz - wx)\\ 2(xz - wy) & 2(yz + wx) & 1-2(x^2+y^2)\end{pmatrix}\)
SLERP \(\displaystyle \mathrm{SLERP}(q_0,q_1,u) = \frac{\sin((1-u)\theta)}{\sin\theta}q_0 + \frac{\sin(u\theta)}{\sin\theta}q_1,\quad \cos\theta = |q_0\cdot q_1|\)
720° \(\displaystyle q(2\pi) = \cos\pi = -1,\qquad q(4\pi) = +1,\qquad \operatorname{tr}R(\theta) = 1 + 2\cos\theta\)

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

Comments
Advertisement