Quats.jl

This package provides a bare-bones representation of attitude transformations through quaternions, rotation vectors, and transformation matrices (a.k.a. direction cosine matrices – DCM).

Installation

Just type:

using Pkg
Pkg.add(url="https://github.com/FraCpl/Quats.jl")

Notation and conventions

Given a 3-dimensional vector $v$, a reference frame $A$ and a reference frame $B$, we indicate with $v^A$ the projection of $v$ into $A$, and with $v^B$ its projection in $B$, so that the two projections can be related through the transformation matrix $R_{AB}$ as follows

\[v^A = R_{AB} v^B\]

The same transformation can be represented using the quaternion $q_{AB}$

\[\begin{bmatrix} 0\\ v^A\end{bmatrix} = q_{AB} ⊗ \begin{bmatrix} 0\\ v^B\end{bmatrix} ⊗ q_{AB}^*\]

In this package, quaternions are represented as 4-dimensional vectors, using the basic vector format natively provided by Julia. The scalar component of the quaternion corresponds to its first element, i.e., q[1]. We use a right-handed passive convention for representing attitude transformations through quaternions, and use $\theta_{AB}$ to indicate the angle by which the frame $A$ needs to be actively rotated to make it coincide with frame $B$ (i.e., the rotation from $A$ to $B$).

Note

Other (and weirder) quaternions notations exist in the litterature, which are obviously not covered by this package.

API

Quats

Quats.q_buildMethod
q_build(qs,qv)

Build a quaternion from its scalar and vectorial components.

source
Quats.q_derivative!Method
q_derivative!(q̇_AB, q_AB, ωAB_B)

Compute the time derivative of a unitary quaternion, given the corresponding angular velocity vector.

Mathematically, this function performs the following operation:

\[q̇_{AB} = \frac{1}{2} q_{AB} ⊗ [0; ω^B_{AB}]\]

where ωAB_B represents the angular velocity of frame $B$ with respect to frame $A$, projected into frame $B$.

source
Quats.q_derivativeMethod
q̇_AB = q_derivative(q_AB, ωAB_B)

Compute the time derivative of a unitary quaternion, given the corresponding angular velocity vector.

Mathematically, this function performs the following operation:

\[q̇_{AB} = \frac{1}{2} q_{AB} ⊗ [0; ω^B_{AB}]\]

where ωAB_B represents the angular velocity of frame $B$ with respect to frame $A$, projected into frame $B$.

source
Quats.q_expMethod
qe = q_exp(q)

Compute the exponential of the input quaternion.

source
Quats.q_fromAxisAngleMethod
q_AB = q_fromAxisAngle(u, θ_AB)

Compute the unitary quaternion given as input an axis-angle representation.

source
Quats.q_fromDcmMethod
q_AB = q_fromDcm(R_AB)

Translate the input rotation matrix into a unitary quaternion.

source
Quats.q_identityMethod
q_identity()

Get identity quaternion, with scalar component equal to 1 and vector components equal to zero.

source
Quats.q_logMethod
ql = q_log(q)

Compute the logarithm of the input quaternion.

source
Quats.q_multiplyMethod
q_AC = q_multiply(q_AB, q_BC)

Mutliply the two input quaternions as follows:

\[q_{AC} = q_{AB} ⊗ q_{BC}\]

source
Quats.q_rateMethod

This uses rotation vector to compute the average angular rate between two sampled quaternion values, knowing that: q[k] = q[k-1] o dq and angRate(t) = dtheta/dt for t in [t[k-1],t[k]] This means that angRate is the equivalent constant average rate that rotates q[k-1] into q[k].

source
Quats.q_slerpMethod
q = q_slerp(q0, q1, τ)

Compute the spherical linear interpolation between two quaternions at τ, where q0 = q[τ=0], q1 = q[τ=1], and q = q[τ].

source
Quats.q_toDcmMethod
R_AB = q_toDcm(q_AB)

Translate the input unitary quaternion into a transformation matrix.

\[R_{AB}(q_{AB}) = I + 2qₛ[qᵥ×] + 2[qᵥ×]²\]

source
Quats.q_tox!Method
q_tox!(xB_A, q_AB)

Compute the x axis of frame B projected in frame A.

source
Quats.q_toxMethod
xB_A = q_tox(q_AB)

Compute the x axis of frame B projected in frame A.

source
Quats.q_toy!Method
q_toy!(yB_A, q_AB)

Compute the y axis of frame B projected in frame A.

source
Quats.q_toyMethod
yB_A = q_toy(q_AB)

Compute the y axis of frame B projected in frame A.

source
Quats.q_toz!Method
q_toz!(zB_A, q_AB)

Compute the z axis of frame B projected in frame A.

source
Quats.q_tozMethod
zB_A = q_toz(q_AB)

Compute the z axis of frame B projected in frame A.

source

Transformation matrices

Quats.dcm_fromAxesMethod
R_AB = dcm_fromAxes(xB_A, yB_A, zB_A)

Compute the transformation matrix given as input the axes of a reference frame.

source
Quats.dcm_fromAxisAngleMethod
R_AB = dcm_fromAxisAngle(u, θ_AB)

Compute the transformation matrix given the axis and angle.

\[R_{AB}(θ_{AB}) = I + \sin(θ_{AB})[u×] + (1 - \cos(θ_{AB}))[u×]^2\]

source

Rotation vectors

Cross product functions

Quats.crossMatMethod
[v×] = crossMat(x, y, z)

Compute the cross product matrix of a vector v given its scalar components.

source
Quats.crossMatSqMethod
[v×]² = crossMatSq(x, y, z)

Compute the squared cross product matrix of a vector v given its scalar components.

source
Quats.crossMatSqMethod
[v×]² = crossMatSq(v)

Compute the squared cross product matrix of a vector v.

source

Index