# Quaternion C++ Class

Here we have provided a C++ class for quaternional algebra. You need these two files: quaternion.h & quaternion.c++. To be able to work with Euler angles, you also need to download Ken Shoemake's QuatTypes.h, EulerAngles.h, EulerAngles.c and define SHOEMAKE in your makefile. Here is an example how to use it all together: (test.c++) and a makefile. For more on quaternions, read Prof. George Francis's introduction lecture.

# Introduction to Quaternionial Algebra

Quaternions are elements of the 4-dimensional space formed by the real axis and 3 imaginary orthogonal axes , , and that obey Hamilton’s rule .  They can be written in a standard quaternionial form as where , or as a 4D vector where is called scalar part and is called vector part.  Quaternions possess the following properties:

Addition: for • closure: • commutativity: • associativity: • identity: there exists such that • inverse: there exists such that • sum: • difference: Multiplication: for and • close: • non-commutativity: • associativity: • distributivity: and • identity: there exists such that • inverse: if , then there exists such that • product: where denotes vector dot product and denotes vector cross product
• no zero divisors: if , then either or • division: , from follows that and • scale:  is the magnitude of , is its norm.  If , the quaternion is referred to as a unit quaternion.  For  is a unit quaternion.  Inverse of is defined as and the conjugate of is defined as .  For any unit quaternion we have .  Quaternions whose real part is zero are called pure quaternions.

Rotation of a 3D vector by a unit quaternion is defined as where is a pure quaternion build from by adding a zero real part.  Sequences of rotations can be conveniently represented as the quaternionial product.  For example, if is rotated by followed by , the result is the same as rotated by .

Document is created by Angela Bennett and Volodymyr Kindratenko