Quaternions

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

Quaternion algebra

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.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
DeformableBodies.Quaternions.normalizeFunction
normalize(q)

Return a Quaternion with the same direction as q but unit norm.

Examples

julia> q = Quaternion([1., 1., 1., 1.])
1.0 + 1.0i + 1.0j + 1.0k

julia> a = normalize(q)
0.5 + 0.5i + 0.5j + 0.5k

julia> abs(a)
1.0
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