# Quaternion

A *quaternion* is an operator that performs a rotation about the origin in 3D space. Conventionally, a quaternion $$\mathbf q$$ is written as

- $$\mathbf q = q_w + q_x \mathbf i + q_y \mathbf j + q_z \mathbf k$$ ,

where the "imaginary" units $$\mathbf i$$, $$\mathbf j$$, and $$\mathbf k$$ all square to $$-1$$.

## Quaternions in 3D Geometric Algebra

The set of quaternions corresponds to a part of the three-dimensional geometric algebra. Specifically, the quaternions are exactly the elements that can be expressed as the sum of a scalar and a 3D bivector. Making the identifications

- $$\mathbf i = -\mathbf e_{23}$$
- $$\mathbf j = -\mathbf e_{31}$$
- $$\mathbf k = -\mathbf e_{12}$$ ,

a quaternion $$\mathbf q$$ can be written as

- $$\mathbf q = q_w - q_x \mathbf e_{23} - q_y \mathbf e_{31} - q_z \mathbf e_{12}$$ .

A *unit quaternion* is one for which $$q_w^2 + q_x^2 + q_y^2 + q_z^2 = 1$$. The inverse of a unit quaternion $$\mathbf q$$ is equal to its reverse $$\mathbf{\tilde q}$$. A unit quaternion can also be written as

- $$\mathbf q = \cos\phi - \mathbf a \sin\phi$$ ,

where $$\mathbf a = a_x \mathbf e_{23} + a_y \mathbf e_{31} + a_z \mathbf e_{12}$$ is a unit bivector representing the axis of rotation, and $$\phi$$ is half the angle of rotation.

A 3D vector $$\mathbf v = v_x \mathbf e_1 + v_y \mathbf e_2 + v_z \mathbf e_3$$ is rotated about the origin by a unit quaternion $$\mathbf q$$ through the sandwich product

- $$\mathbf v' = \mathbf q \mathbin{\unicode{x27D1}} \mathbf v \mathbin{\unicode{x27D1}} \mathbf{\tilde q}$$ .

## Quaternions in 4D Projective Geometric Algebra

The set of quaternions also corresponds to a part of the four-dimensional projective geometric algebra. They are exactly the subset of motors that perform pure rotations about the origin without any translation. In this case, the units $$\mathbf i$$, $$\mathbf j$$, and $$\mathbf k$$ are identified as

- $$\mathbf i = \mathbf e_{41}$$
- $$\mathbf j = \mathbf e_{42}$$
- $$\mathbf k = \mathbf e_{43}$$ .

A quaternion can then be written as

- $$\mathbf q = q_w {\large\unicode{x1D7D9}} + q_x \mathbf e_{41} + q_y \mathbf e_{42} + q_z \mathbf e_{43}$$ ,

and a 3D vector $$\mathbf v$$ is rotated about the origin through the sandwich product

- $$\mathbf v' = \mathbf q \mathbin{\unicode{x27C7}} \mathbf v \mathbin{\unicode{x27C7}} \mathbf{\underset{\Large\unicode{x7E}}{q}}$$ .