# Quaternions

Operations and methods for the algebra of quaternions and rotations. This module is independent from the remainder of DeformableBodies.jl.

## Quaternion algebra

DeformableBodies.QuaternionsModule

Submodule of DeformableBodies.jl implementing quaternion algebra.

Quaternions are a 4-dimensional normed division algebra which extend the complex numbers. They may be used as a representation of rotations on 3-dimensional space.

Exports

source
DeformableBodies.Quaternions.QuaternionType
Quaternion{T<:Real} <: Number

Quaternion type with components of type T.

This type overloads all the arithmetic operations as well as the methods defined for Complex numbers that still make sense for Quaternions.

source
DeformableBodies.Quaternions.quaternionFunction
quaternion(t [,x, y, z])

Convert a real number or an array of real numbers to quaternion.

Examples

julia> quaternion(42)
42 + 0i + 0j + 0k

julia> quaternion([1,2,3])
3-element Array{Quaternion{Int64},1}:
1 + 0i + 0j + 0k
2 + 0i + 0j + 0k
3 + 0i + 0j + 0k
source
quaternion(T::Type)

Return a type representing a quaternion whose components have type T.

Examples

julia> quaternion(Quaternion{Float64})
Quaternion{Float64}

julia> quaternion(Float64)
Quaternion{Float64}
source
DeformableBodies.Quaternions.axisFunction
axis(q)

Return the unit vector on the direction of the imaginary part of a Quaternion.

Examples

julia> Quaternion(10,1,1,0.5)
10.0 + 1.0i + 1.0j + 0.5k

julia> axis(Quaternion(10,1,1,0.5))
3-element Array{Float64,1}:
0.6666666666666666
0.6666666666666666
0.3333333333333333
source

## Rotations

DeformableBodies.Quaternions.rotateFunction
rotate(v::Vector, q::Quaternion, center=zeros(3))
rotate(v::Vector; axis, angle, center=zeros(3))

Rotate a vector v by a quaternion q around a central point center. The quaternion may be given directly or as an axis and an angle. The point pt is optional and defaults to the origin.

source
DeformableBodies.Quaternions.matrixtoquaternionFunction
matrixtoquaternion(R)

Given a rotation matrix R, return a unit quaternion q such that rotate(v,q) = R*v for all v.

The matrix R is assumed to be orthogonal but, for efficiency reasons, no check is made to guarantee that.

Since there are, in general, two unit quaternions representing the same rotation matrix, it is not guaranteed that matrixtoquaternion ∘ quaterniontomatrix equals the identity.

source