Skip to main content

Quaternion Calculator

Our free algebra calculator solves quaternion problems. Get worked examples, visual aids, and downloadable results. See charts, tables, and visual results.

Reviewed by Manoj Kumar, Mathematics Educator

Reviewed by Manoj Kumar, Mathematics Educator

Formula

q = w + xi + yj + zk where i^2 = j^2 = k^2 = ijk = -1

Quaternion multiplication follows Hamilton rules. For unit quaternions, q = cos(theta/2) + sin(theta/2)(xi + yj + zk) represents rotation by angle theta around axis (x,y,z).

Worked Examples

Example 1: Quaternion Multiplication

Problem:Multiply q1 = 1 + 2i + 3j + 4k by q2 = 2 + i - j + 3k.

Solution:Using the quaternion product formula:\nw = (1)(2) - (2)(1) - (3)(-1) - (4)(3) = 2 - 2 + 3 - 12 = -9\nx = (1)(1) + (2)(2) + (3)(3) - (4)(-1) = 1 + 4 + 9 + 4 = 18\ny = (1)(-1) - (2)(3) + (3)(2) + (4)(1) = -1 - 6 + 6 + 4 = 3\nz = (1)(3) + (2)(-1) - (3)(1) + (4)(2) = 3 - 2 - 3 + 8 = 6\nResult: -9 + 18i + 3j + 6k

Result:q1 * q2 = -9 + 18i + 3j + 6k | |q1| = 5.4772, |q2| = 3.8730

Example 2: Rotation Quaternion to Euler Angles

Problem:Convert the unit quaternion q = 0.7071 + 0.7071i + 0j + 0k to Euler angles.

Solution:This quaternion represents a 90-degree rotation about the x-axis.\nq = cos(90/2) + sin(90/2)(1i + 0j + 0k) = cos(45) + sin(45)i\nEuler angles (ZYX convention):\nRoll = atan2(2(0.7071*0.7071 + 0*0), 1 - 2(0.7071^2 + 0^2)) = atan2(1, 0) = 90 degrees\nPitch = asin(2(0.7071*0 - 0*0.7071)) = 0 degrees\nYaw = atan2(2(0.7071*0 + 0.7071*0), 1 - 2(0 + 0)) = 0 degrees

Result:Roll = 90 degrees, Pitch = 0 degrees, Yaw = 0 degrees

Frequently Asked Questions

What is a quaternion and why was it invented?

A quaternion is a four-dimensional number of the form q = w + xi + yj + zk, where w, x, y, z are real numbers and i, j, k are imaginary units satisfying i^2 = j^2 = k^2 = ijk = -1. Quaternions were invented by Sir William Rowan Hamilton in 1843 while walking along the Royal Canal in Dublin, Ireland. He was searching for a way to extend complex numbers to three dimensions but discovered that four dimensions were needed. Quaternions provide a compact and computationally efficient way to represent 3D rotations without the singularity problems (gimbal lock) that plague Euler angle representations.

How does quaternion multiplication work?

Quaternion multiplication follows specific rules derived from the fundamental relations i^2 = j^2 = k^2 = ijk = -1, which also imply ij = k, jk = i, ki = j and their reverses ji = -k, kj = -i, ik = -j. For two quaternions q1 = (w1, x1, y1, z1) and q2 = (w2, x2, y2, z2), the product has: w = w1*w2 - x1*x2 - y1*y2 - z1*z2, x = w1*x2 + x1*w2 + y1*z2 - z1*y2, y = w1*y2 - x1*z2 + y1*w2 + z1*x2, z = w1*z2 + x1*y2 - y1*x2 + z1*w2. Crucially, quaternion multiplication is not commutative, meaning q1*q2 does not generally equal q2*q1.

What is the conjugate and inverse of a quaternion?

The conjugate of a quaternion q = w + xi + yj + zk is q* = w - xi - yj - zk, obtained by negating the vector (imaginary) part while keeping the scalar (real) part unchanged. The magnitude of q is |q| = sqrt(w^2 + x^2 + y^2 + z^2). The inverse of q is q^(-1) = q* / |q|^2, which is the conjugate divided by the squared magnitude. For unit quaternions (|q| = 1), the inverse equals the conjugate, which makes computations particularly efficient. The conjugate of a rotation quaternion represents the reverse rotation, and q * q* = |q|^2 always equals a real number.

References

Reviewed by Manoj Kumar, Mathematics Educator ยท Editorial policy