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$).
Other (and weirder) quaternions notations exist in the litterature, which are obviously not covered by this package.
API
Quats
Quats.q_build — Method
q_build(qs,qv)Build a quaternion from its scalar and vectorial components.
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$.
Quats.q_derivative — Method
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$.
Quats.q_exp — Method
qe = q_exp(q)Compute the exponential of the input quaternion.
Quats.q_fromAxisAngle — Method
q_AB = q_fromAxisAngle(u, θ_AB)Compute the unitary quaternion given as input an axis-angle representation.
Quats.q_fromDcm — Method
q_AB = q_fromDcm(R_AB)Translate the input rotation matrix into a unitary quaternion.
Quats.q_identity — Method
q_identity()Get identity quaternion, with scalar component equal to 1 and vector components equal to zero.
Quats.q_inverse — Method
q⁻¹ = q_inverse(q)Compute the inverse of the input quaternion.
Quats.q_log — Method
ql = q_log(q)Compute the logarithm of the input quaternion.
Quats.q_multiply — Method
q_AC = q_multiply(q_AB, q_BC)Mutliply the two input quaternions as follows:
\[q_{AC} = q_{AB} ⊗ q_{BC}\]
Quats.q_multiplyn — Method
q = q_multiplyn(q1, q2, q3, ...)\[ q = q₁ ⊗ q₂ ⊗ q₃ ⊗ ...\]
Quats.q_random — Method
q_random()Generate a random unitary quaternion.
Quats.q_rate — Method
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].
Quats.q_slerp — Method
q = q_slerp(q0, q1, τ)Compute the spherical linear interpolation between two quaternions at τ, where q0 = q[τ=0], q1 = q[τ=1], and q = q[τ].
Quats.q_toDcm — Method
R_AB = q_toDcm(q_AB)Translate the input unitary quaternion into a transformation matrix.
\[R_{AB}(q_{AB}) = I + 2qₛ[qᵥ×] + 2[qᵥ×]²\]
Quats.q_tox! — Method
q_tox!(xB_A, q_AB)Compute the x axis of frame B projected in frame A.
Quats.q_tox — Method
xB_A = q_tox(q_AB)Compute the x axis of frame B projected in frame A.
Quats.q_toy! — Method
q_toy!(yB_A, q_AB)Compute the y axis of frame B projected in frame A.
Quats.q_toy — Method
yB_A = q_toy(q_AB)Compute the y axis of frame B projected in frame A.
Quats.q_toz! — Method
q_toz!(zB_A, q_AB)Compute the z axis of frame B projected in frame A.
Quats.q_toz — Method
zB_A = q_toz(q_AB)Compute the z axis of frame B projected in frame A.
Quats.q_transformVector! — Method
q_transformVector!(v_A, q_AB, v_B)Project the vector v from frame B into frame A.
Quats.q_transformVector — Method
v_A = q_transformVector(q_AB, v_B)Project the vector v from frame B into frame A.
Quats.q_transformVectorT! — Method
q_transformVectorT!(v_A, q_BA, v_B)Project the vector v from frame B into frame A, using q_BA.
Quats.q_transpose! — Method
q' = q_transpose(q)Transpose the input quaternion.
Transformation matrices
Quats.dcm_fromAxes — Method
R_AB = dcm_fromAxes(xB_A, yB_A, zB_A)Compute the transformation matrix given as input the axes of a reference frame.
Quats.dcm_fromAxisAngle — Method
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\]
Quats.dcm_fromQuaternion — Method
R_AB = dcm_fromQuaternion(q_AB)Compute a transformation matrix from a quaternion.
Quats.dcm_random — Method
dcm_random()Generate a random transformation matrix.
Quats.dcm_toQuaternion — Method
q_AB = dcm_toQuaternion(R_AB)Translate a transformation matrix into a quaternion.
Rotation vectors
Cross product functions
Quats.addCross! — Method
addCross!(a, b, c)Compute a += b × c.
Quats.addCrossSq! — Method
addCrossSq!(a, b, c)Compute a += b × (b × c).
Quats.cross! — Method
cross!(a, b, c)Compute a = b × c.
Quats.crossMat — Method
[v×] = crossMat(x, y, z)Compute the cross product matrix of a vector v given its scalar components.
Quats.crossMat — Method
[v×] = crossMat(v)Compute the cross product matrix of a vector v.
Quats.crossMatSq — Method
[v×]² = crossMatSq(x, y, z)Compute the squared cross product matrix of a vector v given its scalar components.
Quats.crossMatSq — Method
[v×]² = crossMatSq(v)Compute the squared cross product matrix of a vector v.
Quats.crossSq! — Method
crossSq!(a, b, c)Compute a = b × (b × c).
Index
Quats.addCross!Quats.addCrossSq!Quats.cross!Quats.crossMatQuats.crossMatQuats.crossMatSqQuats.crossMatSqQuats.crossSq!Quats.dcm_fromAxesQuats.dcm_fromAxisAngleQuats.dcm_fromQuaternionQuats.dcm_randomQuats.dcm_toQuaternionQuats.q_buildQuats.q_derivativeQuats.q_derivative!Quats.q_expQuats.q_fromAxisAngleQuats.q_fromDcmQuats.q_identityQuats.q_inverseQuats.q_logQuats.q_multiplyQuats.q_multiplynQuats.q_randomQuats.q_rateQuats.q_slerpQuats.q_toDcmQuats.q_toxQuats.q_tox!Quats.q_toyQuats.q_toy!Quats.q_tozQuats.q_toz!Quats.q_transformVectorQuats.q_transformVector!Quats.q_transformVectorT!Quats.q_transpose!