___ _ _ / _ \ _ _ __ _| |_ ___ _ __ _ __ (_) ___ _ __ ___ | | | | | | |/ _` | __/ _ \ '__| '_ \| |/ _ \| '_ \/ __| | |_| | |_| | (_| | || __/ | | | | | | (_) | | | \__ \ \__\_\\__,_|\__,_|\__\___|_| |_| |_|_|\___/|_| |_|___/
I have written a python class for manipulating quaternions. You can download it here. For quick viewing in your browser, click here. This class implements quaternion multiplication and allows quick access to the column vector representation of a quaternion (i.e. (a,b,c,d)^T) as well as the 2x2 complex matrix representation suitable for unit quaternions.
We can represent a quaternion: a+bi+cj+dk in the column vector form described above. We call a the scalar part of the quaternion and b,c,d the vector part of the quaternion.
Scalar multiplication and quaternion addition are defined in the same way as for typical vectors in R^4.
Quaternions have an additional operation of quaternion multiplication, which is non-commutative, and is defined as follows:q1=(a1,b1,c1,d1)^T
A vector x is often transformed to x' using a rotation matrix R using the equation x'=Rx. When we work with quaternions we could convert them to a rotation matrix in order to perform transformations, but we can also perform the transformation directly. A quaternion transforms a vector as follows:
Let q be a unit quaternion (i.e. a quaternion with norm of 1), x a vector to transform.
Create a new quaternion, y from x where the scalar part is 0 and the vector part is x.
And x' is the vector part of y'
We can easily combine a sequence of rotations into a single quaternion using quaternion multiplication as defined above. We can think of this the same way as when combining a sequence of rotation matrices. Start the with first rotation and left multiply it by the subsequent rotations so that the first rotation is on the right and the last rotation is on the far left. For the sequence of rotations q1,...,qn the composite quaternion Q is computed as:qn...q3q2q1=Q
Since my research makes use of reflections on the water surface to estimate depth information it is interesting to note that quaternions can be used for reflecting a vector across a plane. Define the reflection quaternion, q, as a pure quaternion (0 scalar part) with a vector part equal to the unit normal of the plane. Then the reflection r is a pure quaternion of the source quaternion s by the following calculation:r=qsq
Of course, in case of a reflection in a river, the reflection plane is the z axis and source vector s is trivially reflected by replacing its z component with its opposite.