# Quaternion

Quaternion
Field: Geometry
Image Created By: [[Author:| ]]

Quaternion

Quaternions are a number system that work as an extension of complex numbers by having three imaginary components

# Basic Description

Quaternions were discovered by William Rowan Hamilton on 16 October 1843. Quaternions are a number system that work as an extension of complex numbers by having three imaginary components (complex numbers have just one) and one real component.

They are used in theoretical mathematics as well as in applied mathematics, particularly in three dimensional computer graphics.

A quaternion can be represented as

$q = w + xi + yj + zk$

where w is the real component and x,y and z are the imaginary components. The same quaternion can also be expressed as

$q = [ w,(x,y,z) ]$

where w is the “scalar” and v = (x,y,z) is the “vector”. Note, that even though v is called a vector, it is not a typical three dimensional vector but rather a vector in 4D space.

The magnitude of a quaternion is given by:

$magnitude of quaternion$

In case of the imaginary components of the quaternion, the following is true:

$i^{2} = j^{2} = k^{2} = ijk = -1$

# A More Mathematical Explanation

When adding two or more quaternions, the real and imaginary components ar [...]

When adding two or more quaternions, the real and imaginary components are added independently as follows:

$(a_{1} + b_{1}i + c_{1}j + d_{1}k) + (a_{2} + b_{2}i + c_{2}j + d_{2}k) = (a_{1} + a_{2}) + (b_{1} + b_{2}) i + (c_{1} + c_{2}) j + (d_{1} + d_{2}) k$

## Subtracting Quaternions

When subtracting one quaternion from the other, the real and imaginary components of the first are subtractedfrom the real and corresponding imaginary components of the second independently.

$(a_{1} + b_{1}i + c_{1}j + d_{1}k) - (a_{2} + b_{2}i + c_{2}j + d_{2}k) = (a_{1} - a_{2}) + (b_{1} - b_{2}) i + (c_{1} - c_{2}) j + (d_{1} - d_{2}) k$

## Multiplying Quaternions

When multiplying two quaternions, each is placed in brackets and all terms are multiplied out. In case of the imaginary operators, the following rules are followed:

• $i*i=j*j=k*k=-1$
• $i*j = k$
• $j*i = -k$
• $j*k = i$
• $k*j = -i$
• $k*i = j$
• $i*k = -j$

As an example, if you were to multiply two quaternions Q1 (a1+b1i+c1j+d1k) and Q2 (a2+b2i+c2j+d2k), and re-arrange all the terms, this is what you get:

$Q_{1} * Q_{2} = (a_{1}a_{2}-b_{1}b_{2}-c_{1}c_{2}-d_{1}d_{2}) + (a_{1}b_{2}+a_{2}b_{1}+c_{1}d_{2}-d_{1}c_{2})i + (a_{1}c_{2}-b_{1}d_{2}+a_{2}c_{1}+b_{2}d_{1})j + (a_{1}d_{2}+b_{1}c_{2}-b_{2}c_{1}+a_{2}d_{1})k$

Note: The multiplication of quaternions is not commutative. So, Q1 * Q2 does not equal Q2 * Q1. The non-commutative property of multiplication of quaternions has some unexpected consequences. Polynomial equations over quaternions can have more solutions than implied by the degree of the polynomial. For example, the polynomial z2 + 1 = 0 has infinitely many quaternions z = [0,(b,c,d)] (with b2+c2+d2=1) as solutions.

## Identity Quaternions

There are two identity quaternions.

The multiplicative identity quaternion is such that any quaternion multiplied by it will remain unchanged. The multiplicative identity quaternion is:

$Q = [1,(0,0,0)] = 1 + 0i + 0j +0k$

The additive identity quaternion is such that any quaternion added to it remains unchanged. The additive identity quaternion is:

$Q = [0,(0,0,0)] = 0 + 0i + 0j +0k$

## Conjugate of a Quaternion

The conjugate of a quaternion is calculated by reversing the sign of(i.e. negating) the vector part of the quaternion. So, the conjugate of a quaternion, Q would be given by:

$Q^{*} = [Q_{scalar},-Q_{vector}]$

When a quaternion is expressed as a 4x4 matrix, its conjugate corresponds to the transpose of the matrix.

## Quaternion Calculator

Use this quaternion calculator to try your hand at algebra involving quaternions.[1]

# Quaternions in Computer Graphics

Quaternions are used abundantly in the field of computer graphics. They extend the concept of rotation in three dimensions to rotation in four dimensions and allow for the implementation of smooth and continuous rotation. The applied use of quaternions extends beyond computer graphics to robotics, navigation, molecular dynamics and orbital mechanics of satellites.

Quaternions extend the concept of rotation in three dimensions to rotation in four dimensions. This avoids the problem of 'gimbal-lock'.

Gimbal lock is when two rotational axes of an object point in the same direction. Quaternion rotations evaluate all three axes at the same time to evaluate the direction of rotation and a fourth value (the w component) that represents the magnitude of rotation. The advantage of using quaternion rotations is that since all three axes are updated simultaneously, its not possible to arrive at a Gimbal lock.

## Conversion to Rotation Matrix

Quaternions are often used in skeletal animation systems as they provide an efficient means to interpolate the general rotations of joints in a skeleton. However, matrices are more efficient when many points or vertices need to be transformed. Thus the need to convert quaternions to rotational matrices arises.

For the quaternion, Q[w,(x,y,z)], the equivalent rotation matrix is given by:

$Matrix = \begin{bmatrix}w^{2}+x^{2}-y^{2}-z^{2} & 2xy - 2wz & 2xz + 2wy\\ 2xy + 2wz & w^{2}-x^{2}+y^{2}-z^{2} & 2yz - 2wx\\ 2xz-2wy & 2yz + 2wx & w^{2}-x^{2}-y^{2}+z^{2}\\ \end{bmatrix}$

[[Category:]]