A quaternion is a rotation stored as 4 numbers . When you rotate by q 1 q_1 q 1 and then by q 2 q_2 q 2 , the combined rotation is a single quaternion. The Hamilton product is the rule that tells you how to multiply two rotations into one. It is the quaternion version of "stacking rotation matrices" — but with only 4 numbers and no trig.
WHY care in GNC? A spacecraft/drone attitude filter (like a MEKF or complementary filter) integrates gyro data as tiny quaternion multiplications every millisecond. Get the product rule wrong → your attitude drifts or flips. This is the arithmetic of orientation.
A quaternion is q = w + x i + y j + z k q = w + x\,i + y\,j + z\,k q = w + x i + y j + z k , four real numbers with three imaginary units obeying Hamilton's rules:
i 2 = j 2 = k 2 = i j k = − 1 i^2 = j^2 = k^2 = ijk = -1 i 2 = j 2 = k 2 = ij k = − 1
We write it as a scalar + vector pair:
q = ( w , v ) , v = ( x , y , z ) q = (w,\ \mathbf{v}), \qquad \mathbf{v} = (x,y,z) q = ( w , v ) , v = ( x , y , z )
The scalar w w w is the real (scalar) part ; v \mathbf{v} v is the vector (imaginary) part .
From i j k = − 1 ijk=-1 ij k = − 1 and squaring rules, the pairwise products follow (this is the whole engine):
i j = k , j k = i , k i = j (cyclic, right-handed) ij = k,\quad jk = i,\quad ki = j \qquad\text{(cyclic, right-handed)} ij = k , j k = i , k i = j (cyclic, right-handed)
j i = − k , k j = − i , i k = − j (anti-cyclic) ji = -k,\quad kj = -i,\quad ik = -j \qquad\text{(anti-cyclic)} j i = − k , k j = − i , ik = − j (anti-cyclic)
Intuition Why do these signs exist?
i , j , k i,j,k i , j , k behave like the coordinate axes of a right-handed frame under cross product: x ^ × y ^ = z ^ \hat x \times \hat y = \hat z x ^ × y ^ = z ^ etc. That's where i j = k ij=k ij = k comes from. But they also square to − 1 -1 − 1 like the complex i i i . The Hamilton product fuses a cross product (rotation-like) with a dot product (alignment/shrinking) into one operation. Non-commutativity (i j ≠ j i ij \ne ji ij = j i ) is not a bug — rotations in 3D genuinely don't commute.
Compute i j i\,j i j using the vector formula.
p = i p=i p = i : w 1 = 0 , v 1 = ( 1 , 0 , 0 ) w_1=0,\ \mathbf{v}_1=(1,0,0) w 1 = 0 , v 1 = ( 1 , 0 , 0 ) . Why? i i i is a pure-vector unit quaternion.
q = j q=j q = j : w 2 = 0 , v 2 = ( 0 , 1 , 0 ) w_2=0,\ \mathbf{v}_2=(0,1,0) w 2 = 0 , v 2 = ( 0 , 1 , 0 ) .
scalar = 0 − ( 1 , 0 , 0 ) ⋅ ( 0 , 1 , 0 ) = 0 = 0 - (1,0,0)\!\cdot\!(0,1,0) = 0 = 0 − ( 1 , 0 , 0 ) ⋅ ( 0 , 1 , 0 ) = 0 . Why? v 1 ⊥ v 2 \mathbf v_1 \perp \mathbf v_2 v 1 ⊥ v 2 , dot is 0.
vector = 0 + 0 + ( 1 , 0 , 0 ) × ( 0 , 1 , 0 ) = ( 0 , 0 , 1 ) = 0 + 0 + (1,0,0)\times(0,1,0) = (0,0,1) = 0 + 0 + ( 1 , 0 , 0 ) × ( 0 , 1 , 0 ) = ( 0 , 0 , 1 ) . Why? right-hand cross gives z ^ \hat z z ^ .
Result = ( 0 , ( 0 , 0 , 1 ) ) = k =(0,(0,0,1)) = k = ( 0 , ( 0 , 0 , 1 )) = k . ✅ matches i j = k ij=k ij = k .
Now j i j\,i j i : cross flips to ( 0 , 0 , − 1 ) (0,0,-1) ( 0 , 0 , − 1 ) → result − k -k − k . Why this step? cross product is anti-commutative, so swapping order flips sign. This proves i j = − j i ij=-ji ij = − j i .
Rotate 90 ∘ 90^\circ 9 0 ∘ about z z z , then 90 ∘ 90^\circ 9 0 ∘ about x x x . Unit quaternion for angle θ \theta θ about axis n ^ \hat n n ^ is q = ( cos θ 2 , sin θ 2 n ^ ) q = (\cos\frac\theta2,\ \sin\frac\theta2\,\hat n) q = ( cos 2 θ , sin 2 θ n ^ ) .
q z = ( cos 45 ∘ , ( 0 , 0 , sin 45 ∘ ) ) = ( 1 2 , 0 , 0 , 1 2 ) q_z = (\cos45^\circ, (0,0,\sin45^\circ)) = (\tfrac{1}{\sqrt2}, 0,0,\tfrac{1}{\sqrt2}) q z = ( cos 4 5 ∘ , ( 0 , 0 , sin 4 5 ∘ )) = ( 2 1 , 0 , 0 , 2 1 )
q x = ( 1 2 , 1 2 , 0 , 0 ) q_x = (\tfrac{1}{\sqrt2}, \tfrac{1}{\sqrt2},0,0) q x = ( 2 1 , 2 1 , 0 , 0 )
Combined rotation ("x x x after z z z ") = q x q z q_x \, q_z q x q z (leftmost applied last). Why? Hamilton convention: q total = q last q first q_{\text{total}} = q_{\text{last}}\,q_{\text{first}} q total = q last q first .
w = w 1 w 2 − v 1 ⋅ v 2 = 1 2 − ( 1 2 , 0 , 0 ) ⋅ ( 0 , 0 , 1 2 ) = 1 2 − 0 = 1 2 w = w_1w_2 - \mathbf v_1\!\cdot\!\mathbf v_2 = \tfrac12 - (\tfrac{1}{\sqrt2},0,0)\!\cdot\!(0,0,\tfrac{1}{\sqrt2}) = \tfrac12 - 0 = \tfrac12 w = w 1 w 2 − v 1 ⋅ v 2 = 2 1 − ( 2 1 , 0 , 0 ) ⋅ ( 0 , 0 , 2 1 ) = 2 1 − 0 = 2 1
v = w 1 v 2 + w 2 v 1 + v 1 × v 2 \mathbf v = w_1\mathbf v_2 + w_2\mathbf v_1 + \mathbf v_1\times\mathbf v_2 v = w 1 v 2 + w 2 v 1 + v 1 × v 2
= 1 2 ( 0 , 0 , 1 2 ) + 1 2 ( 1 2 , 0 , 0 ) + ( 1 2 , 0 , 0 ) × ( 0 , 0 , 1 2 ) = \tfrac{1}{\sqrt2}(0,0,\tfrac{1}{\sqrt2}) + \tfrac{1}{\sqrt2}(\tfrac{1}{\sqrt2},0,0) + (\tfrac{1}{\sqrt2},0,0)\times(0,0,\tfrac{1}{\sqrt2}) = 2 1 ( 0 , 0 , 2 1 ) + 2 1 ( 2 1 , 0 , 0 ) + ( 2 1 , 0 , 0 ) × ( 0 , 0 , 2 1 )
= ( 0 , 0 , 1 2 ) + ( 1 2 , 0 , 0 ) + ( 0 , − 1 2 , 0 ) = ( 1 2 , − 1 2 , 1 2 ) = (0,0,\tfrac12) + (\tfrac12,0,0) + (0,-\tfrac12,0) = (\tfrac12,-\tfrac12,\tfrac12) = ( 0 , 0 , 2 1 ) + ( 2 1 , 0 , 0 ) + ( 0 , − 2 1 , 0 ) = ( 2 1 , − 2 1 , 2 1 )
So q x q z = ( 1 2 , 1 2 , − 1 2 , 1 2 ) q_xq_z = (\tfrac12, \tfrac12,-\tfrac12,\tfrac12) q x q z = ( 2 1 , 2 1 , − 2 1 , 2 1 ) . Check: norm = 4 ⋅ 1 4 = 1 =\sqrt{4\cdot\tfrac14}=1 = 4 ⋅ 4 1 = 1 ✅ (product of unit quaternions is unit — that's why gyro integration keeps orientations valid).
Definition Sandwich / conjugation
To rotate a 3D vector u \mathbf u u , embed it as a pure quaternion u = ( 0 , u ) u=(0,\mathbf u) u = ( 0 , u ) and compute
u ′ = q u q − 1 , q − 1 = q ˉ / ∣ q ∣ 2 , q ˉ = ( w , − v ) u' = q\,u\,q^{-1}, \qquad q^{-1} = \bar q/|q|^2,\ \ \bar q = (w,-\mathbf v) u ′ = q u q − 1 , q − 1 = q ˉ /∣ q ∣ 2 , q ˉ = ( w , − v )
For unit q q q , q − 1 = q ˉ q^{-1}=\bar q q − 1 = q ˉ . Two Hamilton products give the rotated vector.
Why a sandwich and not just q u qu q u ? A single product would mix scalar and vector parts and change length. The conjugation q ( ⋅ ) q − 1 q(\cdot)q^{-1} q ( ⋅ ) q − 1 cancels the scalar leakage and applies the rotation twice-by-half , which is why the half-angle θ / 2 \theta/2 θ /2 appears in q q q .
Common mistake Multiplying in the wrong order
Wrong feels right: "I did rotation A then B, so multiply q A q B q_A q_B q A q B left-to-right like reading."
Fix: Hamilton convention applies rotations right-to-left : q B q A q_B q_A q B q A means "A A A first, then B B B ." Test with Example 1: i j = k ij=k ij = k but j i = − k ji=-k j i = − k . Order matters. Pick a convention, write it on the whiteboard, never switch mid-project.
Common mistake Forgetting to normalize
Wrong feels right: "Products of unit quaternions stay unit, so I never renormalize."
Fix: Exactly true in math, but floating-point rounding accumulates error over thousands of gyro updates. Renormalize q ← q / ∣ q ∣ q \leftarrow q/|q| q ← q /∣ q ∣ periodically.
Common mistake Treating the vector part like a plain 3-vector product
Wrong feels right: "v 1 × v 2 \mathbf v_1 \times \mathbf v_2 v 1 × v 2 alone is the vector part."
Fix: You must add the scalar-scaling terms w 1 v 2 + w 2 v 1 w_1\mathbf v_2 + w_2\mathbf v_1 w 1 v 2 + w 2 v 1 . Dropping them silently loses all pure-spin information.
i j k = − 1 ijk=-1 ij k = − 1 with commuting
Wrong feels right: "i j k = − 1 ijk=-1 ij k = − 1 and i 2 = − 1 i^2=-1 i 2 = − 1 , so it's just complex-number arithmetic scaled up."
Fix: In C \mathbb C C , a b = b a ab=ba ab = ba . Here i j ≠ j i ij\ne ji ij = j i . Quaternions are a non-commutative division algebra — that non-commutativity is precisely 3D rotation.
Recall Flashables (hide and test yourself)
What are the two parts of the Hamilton product? scalar = w 1 w 2 − v 1 ⋅ v 2 =w_1w_2-\mathbf v_1\!\cdot\!\mathbf v_2 = w 1 w 2 − v 1 ⋅ v 2 ; vector = w 1 v 2 + w 2 v 1 + v 1 × v 2 =w_1\mathbf v_2+w_2\mathbf v_1+\mathbf v_1\times\mathbf v_2 = w 1 v 2 + w 2 v 1 + v 1 × v 2 .
Sole source of non-commutativity? the cross product term.
i j = ? ij=? ij = ? = k \;=k = k . j i = ? ji=? j i = ? = − k \;=-k = − k .
How to rotate a vector? q u q ˉ q\,u\,\bar q q u q ˉ for unit q q q .
Recall Feynman: explain to a 12-year-old
Imagine two magic "turn cards." Each card, when you tap it, spins a toy in space. If you want one card that does both spins at once, you glue the two cards together with a special recipe. The recipe has two ingredients: one part checks how much the two spins point the same way (that's the dot part, a plain number), and the other part checks how much they twist across each other (that's the cross part, which points sideways by the right-hand rule). Because twisting-across depends on which card you tap first, tapping card A then B is not the same as B then A — just like turning a Rubik's cube.
"Scalar Says: Multiply-minus-Dot. Vector Vibes: two Weights plus a Cross."
w 1 w 2 − v 1 ⋅ v 2 w_1w_2 - \mathbf v_1\!\cdot\!\mathbf v_2 w 1 w 2 − v 1 ⋅ v 2 | w 1 v 2 + w 2 v 1 + v 1 × v 2 w_1\mathbf v_2 + w_2\mathbf v_1 + \mathbf v_1\times\mathbf v_2 w 1 v 2 + w 2 v 1 + v 1 × v 2 .
Rotation Matrices — SO(3) — the Hamilton product ≡ matrix multiplication of rotations.
Axis-Angle & Euler Rodrigues — where the half-angle θ / 2 \theta/2 θ /2 inside q q q comes from.
Quaternion Kinematics — $\dot q = \tfrac12 q\,\omega$ — gyro integration uses this product.
Multiplicative EKF (MEKF) — attitude filters chain Hamilton products.
Gimbal Lock & Euler Angles — the problem quaternions solve.
Cross Product & Right-Hand Rule — the geometric root of i j = k ij=k ij = k .
Hamilton product scalar part w 1 w 2 − v 1 ⋅ v 2 w_1w_2 - \mathbf v_1\cdot\mathbf v_2 w 1 w 2 − v 1 ⋅ v 2 Hamilton product vector part w 1 v 2 + w 2 v 1 + v 1 × v 2 w_1\mathbf v_2 + w_2\mathbf v_1 + \mathbf v_1\times\mathbf v_2 w 1 v 2 + w 2 v 1 + v 1 × v 2 Which term causes non-commutativity the cross product
v 1 × v 2 \mathbf v_1\times\mathbf v_2 v 1 × v 2 Value of i j ij ij Value of j i ji j i Fundamental relation defining quaternions i 2 = j 2 = k 2 = i j k = − 1 i^2=j^2=k^2=ijk=-1 i 2 = j 2 = k 2 = ij k = − 1 Order convention: rotation A then B combined quaternion q B q A q_B q_A q B q A (right-to-left)
How to rotate vector u by unit quaternion q u ′ = q u q ˉ u' = q\,u\,\bar q u ′ = q u q ˉ Inverse of a unit quaternion its conjugate
q ˉ = ( w , − v ) \bar q=(w,-\mathbf v) q ˉ = ( w , − v ) Is the product of two unit quaternions a unit quaternion Yes,
∣ p q ∣ = ∣ p ∣ ∣ q ∣ |pq|=|p||q| ∣ pq ∣ = ∣ p ∣∣ q ∣
Quaternion w plus xi yj zk
Hamilton rules i2 j2 k2 ijk eq -1
Multiplication table ij eq k etc
Scalar part w1w2 minus v1 dot v2
Vector part w1v2 plus w2v1 plus cross
Attitude filter MEKF gyro integration
Intuition Hinglish mein samjho
Dekho, quaternion ek chhota sa 4-number ka packet hai jo ek rotation ko store karta hai: ek scalar part w w w aur ek vector part ( x , y , z ) (x,y,z) ( x , y , z ) . Jab aap do rotations ko ek ke baad ek lagate ho, to unko combine karne ka rule hi Hamilton product hai. Yeh basically rotation matrices ko multiply karne jaisa hai, but sirf 4 numbers ke saath, koi bhaari trigonometry nahi.
Formula ka core simple hai agar aap scalar+vector notation mein soch lo: scalar part ban-ta hai w 1 w 2 − v 1 ⋅ v 2 w_1w_2 - \mathbf v_1\cdot\mathbf v_2 w 1 w 2 − v 1 ⋅ v 2 (dot product wala minus), aur vector part ban-ta hai w 1 v 2 + w 2 v 1 + v 1 × v 2 w_1\mathbf v_2 + w_2\mathbf v_1 + \mathbf v_1\times\mathbf v_2 w 1 v 2 + w 2 v 1 + v 1 × v 2 . Yeh koi rata-fied formula nahi hai — bas i , j , k i,j,k i , j , k ke rules (i j = k ij=k ij = k , j i = − k ji=-k j i = − k , i j k = − 1 ijk=-1 ij k = − 1 ) laga ke distribute karo, sab ingredients apne aap aa jaate hain. Sabse important cheez: sirf cross product term hi non-symmetric hai, isiliye p q ≠ q p pq \ne qp pq = q p — matlab pehle A phir B, aur pehle B phir A, dono alag results dete hain. Yeh natural hai kyunki 3D mein rotations sach mein commute nahi karte (Rubik's cube ki tarah).
GNC mein iska matlab bahut bada hai: drone ya satellite ka attitude filter har millisecond gyro ka data lekar ek tiny quaternion multiply karta hai. Agar aap order ulta kar do ya normalize karna bhool jao, to orientation drift ya flip ho jaayega. Convention: q total = q last q first q_{\text{total}} = q_{\text{last}}\, q_{\text{first}} q total = q last q first , yaad rakho — right se left. Aur vector ko rotate karne ke liye sandwich formula q u q ˉ q\,u\,\bar q q u q ˉ use hota hai, jisme half-angle θ / 2 \theta/2 θ /2 isiliye aata hai kyunki rotation do baar half apply hota hai. Bas yeh clear ho gaya to poora quaternion attitude control aapka.