Quaternions
Quaternions are best known for their suitability as representations of 3D rotational orientation. They can also be viewed as an extension of complex numbers.
Many softwares such as SciPy and ROS, they treat the order of a quaternion as , but not . One reason for that is that the order in swizzling is xyzw
.
However, most Julia packages use order. This is for consistency with Base.Complex
's order.
Packages for Quaternions
Quaternions.jl
Quaternions.jl is the most popular Julia package for quaternions.This package implements
Quaternions.Quaternion
which is much similar toBase.Complex
.This package focus on some basic operations for quaternions. Most implemented methods are added to
Base
functions.Other operations such as rotations are not implemented in this package. Use Rotations.jl instead.
The arguments for
Quaternions.Quaternion
is ordered in .
Historically, this package was not actively maintained before 2022.
Quaternionic.jl
Quaternionic.jl is another Julia package for quaternions.This package exports
AbstractQuaternion
as well as three concrete subtypes:Quaternion
for arbitrary quaternions,Rotor
for quaternions with unit magnitude, andQuatVec
for quaternions with zero scalar part (corresponding to ordinary three-vectors). These allows specializations for faster and/or more precise results in those special cases.Each of the types parametrizes the type
T
of its components, as inQuaternionic.Quaternion{T}
, but does not requireT <: Real
. As a result, this package can handle biquaternions for example.This package exports
imx
,imy
, andimz
(similar toBase.im
), and their unicode counterpartsš¢
,š£
, andš¤
.Special care is taken to ensure that functions such as
log
,exp
,sqrt
, etc., are accurate and smooth near singularities and branch cuts, and to ensure that they are differentiable at those points. In particularChainRules
andForwardDiff
are explicitly supported.Methods are directly included to permit transformation to and from various representations of rotations, such as Euler angles, spherical coordinates, axis-angle, and rotation-matrix representations.
Several functions are included to find the optimal rotation to align two sets of points, or the optimal rotor to align two sets of rotors, and to measure distances between quaternions or rotors.
This package also enables various ways of dealing with quaternion-valued functions of time, including
Linear interpolation, or
slerp
Quadratic interpolation, or
squad
Conversion to and from angular velocity as a function of time
Conversion to the "minimal-rotation" frame
The arguments for
Quaternionic.Quaternion
is ordered in .
Packages that define their own Quaternions
Makie.jl
Makie.jl has its ownQuaternion
type, but this should be replaced with Quaternions.Quaternion
. Please check comment in Makie.jl/src/utilities/quaternions.jl. Note that Makie.Quaternion
uses order. ReferenceFrameRotations.jl
ReferenceFrameRotations.jl also has its ownQuaternion
type. There was an issue#25 to be compatible with Quaternions.jl. Grassmann.jl
Grassmann.jl does not implementQuaternion
as a struct, but quaternions are realized as an alias Grassmann.Quaternion (alias for Spinor{V, T, 4} where {V, T})
. Comparison of quaternions in the context of Grassmann
to other quaternion implementations is characterized by syntax design differences to fit into a larger mathematical formalism. Differences such as performance or edge cases can always be smoothed out, while syntax and design choices are fundamentally different. With Grassmann
geometric algebra it is possible to achieve much more out of quaternions due to the immediate access to its fully general mathematical formalism.
Quaternion algebra exists as a specialized sub-algebra within a more general Grassmann
geometric algebra, where the goal is to seamlessly transition between quaternion abstractions and further combinatorial generalizations. There are several ways to assign i,j,k
with Grassmann
elements, perhaps the standard would be i = v12
, j = -v13
, k = v23
(although this is not a unique choice). Since j
and v13
have opposite sign in this notation, the quatvalues
method is exported to output the coefficients with the sign convention of s,i,j,k
.
assign
Grassmann
elements for quaternion usage:using Grassmann; basis"3"
basis:
v, vā, vā, vā, vāā, vāā, vāā, vāāā
orv, v1, v2, v3, v12, v13, v23, v123
assign quaternion basis:
s, i, j, k = v, v12, -v13, v23
could be a standard choicequatvalues(::Quaternion)
returns the coefficient values according tos, i, j, k
quaternion(s,i,j,k)
returns theGrassmann
quaternion from thes, i, j, k
standard
As a result of the framework of geometric algebra implemented in Grassmann
, vector algebra and quaternion algebra are compatible in a unified formalism. Given a quaternion operator R
and a vector x
the operator can be applied with either the R>>>x
(evaluated as R*x*conj(R)
operator) or xāR
(evaluated as conj(R)*x*R
operator) to transform vectors with quaternions. Converting a quaternion operator R
on a three dimensional vector to a matrix (with the xāR
evaluation) can be done with Matrix(operator(R))
for convenience.
In the traditional quaternion packages there is only access to a limited mathematical scope constrained to rotations in three dimensions, while in Grassmann
there are rotational algebras for lower and higher dimensions and it is also natural to deal with reflection operator compositions and more. This developer (for example), will feel a loss of mathematical expressibility when downgrading from Grassmann
to a more limited quaternion formalism, as Grassmann
can express the full graded algebra structure compared to the mere sub-algebra of quaternions. Programming using a more general and sophisticated mathematical formalism typically involves a more abstract and verbose syntax, and this is the case for Grassman.jl as compared to Quaternions.jl
Related discourse posts
Last modified: May 03, 2024. Built with Franklin.jl