Library

Documentation for ReferenceFrameRotations.jl.

Core.TupleMethod
Tuple(dcm::DCM{T}) where {T} -> NTuple{9, T}

Return the column-major elements of dcm as a tuple.

source
ReferenceFrameRotations.CRPType
struct CRP{T}

Represent Classical Rodrigues Parameters (CRP).

Fields

  • q1::T: First dimensionless CRP component [-].
  • q2::T: Second dimensionless CRP component [-].
  • q3::T: Third dimensionless CRP component [-].
source
ReferenceFrameRotations.CRPMethod
CRP(v::AbstractVector) -> CRP
CRP(::UniformScaling{T}) where {T} -> CRP{T}

Construct a CRP from the three-component vector v.

source
ReferenceFrameRotations.DCMType
struct DCM{T}

Store a Direction Cosine Matrix (DCM) whose nine elements have type T.

Fields

  • data::NTuple{9, T}: Matrix elements in column-major order.

Examples

julia> DCM(1.0I)
DCM{Float64}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0

julia> DCM([1 0 0; 0 -1 0; 0 0 -1])
DCM{Int64}:
 1   0   0
 0  -1   0
 0   0  -1
source
ReferenceFrameRotations.EulerAngleAxisType
struct EulerAngleAxis{T}

Represent a 3D rotation with an Euler angle and axis.

Fields

  • a::T: The Euler angle [rad].
  • v::SVector{3, T}: Vector aligned with the Euler axis; callers must provide a unit vector.

Examples

julia> EulerAngleAxis(pi / 3, [sqrt(2) / 2, sqrt(2) / 2, 0])
EulerAngleAxis{Float64}:
  Euler angle : 1.0472 rad  (60.0°)
  Euler axis  : [0.707107, 0.707107, 0.0]
source
ReferenceFrameRotations.EulerAngleAxisMethod
EulerAngleAxis(a::Any, v::AbstractVector) -> EulerAngleAxis

Construct an Euler angle and axis from a [rad] and the three-component vector v. Do not assume that v is normalized; this constructor does not normalize it, so callers must provide a unit axis when a valid rotation representation is required.

source
ReferenceFrameRotations.EulerAnglesType
struct EulerAngles{T}

Store three Euler angles a1, a2, and a3 together with a rotation sequence rot_seq.

Fields

  • a1::T: First rotation [rad].
  • a2::T: Second rotation [rad].
  • a3::T: Third rotation [rad].
  • rot_seq::Symbol: Rotation sequence.
Info

rot_seq is provided by a symbol with three characters, each one indicating the rotation axis of the corresponding angle, e.g. :ZYX. The valid values for rot_seq are:

  • :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ.

Examples

julia> EulerAngles(pi / 2, pi / 4, -pi, :XYZ)
EulerAngles{Float64}:
  R(X) :  1.5708   rad  ( 90.0°)
  R(Y) :  0.785398 rad  ( 45.0°)
  R(Z) : -3.14159  rad  (-180.0°)
source
ReferenceFrameRotations.EulerAnglesMethod
EulerAngles(a1::Any, a2::Any, a3::Any, rot_seq::Symbol = :ZYX) -> EulerAngles

Construct Euler angles a1, a2, and a3 [rad] with rotation sequence rot_seq.

Note

This constructor does not validate rot_seq. Conversions require it to be one of the supported rotation sequences listed for EulerAngles; otherwise, they throw an ArgumentError.

source
ReferenceFrameRotations.MRPType
struct MRP{T}

Represent Modified Rodrigues Parameters (MRP).

Fields

  • q1::T: First dimensionless MRP component [-].
  • q2::T: Second dimensionless MRP component [-].
  • q3::T: Third dimensionless MRP component [-].
source
ReferenceFrameRotations.MRPMethod
MRP(v::AbstractVector) -> MRP
MRP(::UniformScaling{T}) where {T} -> MRP{T}

Construct an MRP from the three-component vector v.

source
ReferenceFrameRotations.QuaternionType
struct Quaternion{T}

Represent a quaternion with scalar-first components.

Fields

  • q0::T: Quaternion real part.
  • q1::T: X component of the quaternion imaginary part.
  • q2::T: Y component of the quaternion imaginary part.
  • q3::T: Z component of the quaternion imaginary part.
Note

The quaternion q in this structure is represented by:

q = q0 + q1.i + q2.j + q3.k

Example

julia> Quaternion(cosd(45), sind(45), 0, 0)
Quaternion{Float64}:
  + 0.707107 + 0.707107⋅i + 0.0⋅j + 0.0⋅k
source
ReferenceFrameRotations.QuaternionMethod
Quaternion(q0::Any, q1::Any, q2::Any, q3::Any) -> Quaternion
Quaternion(v::AbstractVector) -> Quaternion
Quaternion(r::Number, v::AbstractVector) -> Quaternion
Quaternion(u::UniformScaling{T}) where {T} -> Quaternion{T}
Quaternion{T}(u::UniformScaling) where {T} -> Quaternion{T}
Quaternion(u::UniformScaling, q::Quaternion{T}) where {T} -> Quaternion{T}

Create the following quaternion:

q0 + q1.i + q2.j + q3.k

in which:

  • q0 is the real part of the quaternion.
  • q1 is the X component of the quaternion vectorial part.
  • q2 is the Y component of the quaternion vectorial part.
  • q3 is the Z component of the quaternion vectorial part.
Note

The quaternion element type is obtained by promoting the types of q0, q1, q2, and q3.

Examples

julia> Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> Quaternion(1, 0, 0, 0.0)
Quaternion{Float64}:
  + 1.0 + 0.0⋅i + 0.0⋅j + 0.0⋅k

Quaternion(v::AbstractVector) -> Quaternion

If the vector v has 3 components, then create a quaternion in which the real part is 0 and the vectorial or imaginary part has the same components of the vector v. In other words:

q = 0 + v[1].i + v[2].j + v[3].k

Otherwise, if the vector v has 4 components, then create a quaternion in which the elements match those of the input vector:

q = v[1] + v[2].i + v[3].j + v[4].k
Note

If the length of v is not 3 or 4, then an error is thrown.

Examples

julia> Quaternion([0, cosd(45), sind(45)])
Quaternion{Float64}:
  + 0.0 + 0.0⋅i + 0.707107⋅j + 0.707107⋅k

julia> Quaternion([cosd(45), 0, sind(45), 0])
Quaternion{Float64}:
  + 0.707107 + 0.0⋅i + 0.707107⋅j + 0.0⋅k

Quaternion(r::Number, v::AbstractVector) -> Quaternion

Create a quaternion with real part r and vectorial or imaginary part v:

r + v[1].i + v[2].j + v[3].k
Note

The quaternion type is obtained by promoting the type of r and the elements of v. The vector v must have exactly 3 components; otherwise, an ArgumentError is thrown.

Examples

julia> Quaternion(cosd(45), [0, sind(45), 0])
Quaternion{Float64}:
  + 0.707107 + 0.0⋅i + 0.707107⋅j + 0.0⋅k

Create the quaternion u.λ + 0.i + 0.j + 0.k.

If a quaternion is passed as in the sixth signature, then the new quaternion will have the same element type as it.

Examples

julia> Quaternion(I)
Quaternion{Bool}:
  + true + false⋅i + false⋅j + false⋅k

julia> Quaternion(1.0I)
Quaternion{Float64}:
  + 1.0 + 0.0⋅i + 0.0⋅j + 0.0⋅k

julia> q = Quaternion{Float32}(I)
Quaternion{Float32}:
  + 1.0 + 0.0⋅i + 0.0⋅j + 0.0⋅k

julia> Quaternion(I, q)
Quaternion{Float32}:
  + 1.0 + 0.0⋅i + 0.0⋅j + 0.0⋅k
source
Base.:*Method
*(v::AbstractVector, q::Quaternion) -> Quaternion
*(q::Quaternion, v::AbstractVector) -> Quaternion

Compute the multiplication qv * q or q * qv in which qv is a quaternion with real part 0 and vectorial/imaginary part v (Hamilton product).

Examples

julia> q = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> v = [0, cosd(60), sind(60)]
3-element Vector{Float64}:
 0.0
 0.5
 0.8660254037844386

julia> q * v
Quaternion{Float64}:
  + 0.0 + 0.0⋅i + 0.5⋅j + 0.866025⋅k
source
Base.:*Method
*(c1::CRP, c2::CRP) -> CRP

Compute the composition of the CRPs c1 and c2, which is the rotation c2 followed by the rotation c1.

Warning

Throw an ArgumentError if the composition is singular, which happens when it represents a 180° rotation.

source
Base.:*Method
*(Θ₂::EulerAngles, Θ₁::EulerAngles) -> EulerAngles

Compose Θ₁ followed by Θ₂.

Represent the result with Euler angles (see EulerAngles) with the same rotation sequence as Θ₂.

Examples

julia> ea1 = EulerAngles(deg2rad(35), 0, 0, :XYZ)
EulerAngles{Float64}:
  R(X) :  0.610865 rad  ( 35.0°)
  R(Y) :  0.0      rad  ( 0.0°)
  R(Z) :  0.0      rad  ( 0.0°)

julia> ea2 = EulerAngles(0, 0, deg2rad(25), :ZYX)
EulerAngles{Float64}:
  R(Z) :  0.0      rad  ( 0.0°)
  R(Y) :  0.0      rad  ( 0.0°)
  R(X) :  0.436332 rad  ( 25.0°)

julia> ea2 * ea1
EulerAngles{Float64}:
  R(Z) :  0.0    rad  ( 0.0°)
  R(Y) :  0.0    rad  ( 0.0°)
  R(X) :  1.0472 rad  ( 60.0°)
source
Base.:*Method
*(m1::MRP, m2::MRP) -> MRP

Compute the composition of the MRPs m1 and m2, which is the rotation m2 followed by the rotation m1.

Warning

Throw an ArgumentError if the composition is singular, which happens when it represents a 360° rotation.

source
Base.:*Method
*(λ::Number, c::CRP) -> CRP
*(c::CRP, λ::Number) -> CRP

Scale c by the scalar λ.

source
Base.:*Method
*(λ::Number, m::MRP) -> MRP
*(m::MRP, λ::Number) -> MRP

Scale m by the scalar λ.

source
Base.:*Method
*(λ::Number, q::Quaternion) -> Quaternion
*(q::Quaternion, λ::Number) -> Quaternion

Compute λ * q or q * λ, in which λ is a scalar.

Examples

julia> q = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> 2 * q
Quaternion{Int64}:
  + 2 + 0⋅i + 0⋅j + 0⋅k
source
Base.:*Method
*(q1::Quaternion, q2::Quaternion) -> Quaternion

Compute the quaternion multiplication q1 * q2 (Hamilton product).

If one of the operands is a UniformScaling:

*(u::UniformScaling, q::Quaternion)
*(q::Quaternion, u::UniformScaling)

then it is considered as the quaternion u.λ + 0 ⋅ i + 0 ⋅ j + 0 ⋅ k.

Examples

julia> q1 = Quaternion(cosd(30), 0, sind(30), 0)
Quaternion{Float64}:
  + 0.866025 + 0.0⋅i + 0.5⋅j + 0.0⋅k

julia> q2 = Quaternion(cosd(60), 0, sind(60), 0)
Quaternion{Float64}:
  + 0.5 + 0.0⋅i + 0.866025⋅j + 0.0⋅k

julia> q1 * q2
Quaternion{Float64}:
  + 0.0 + 0.0⋅i + 1.0⋅j + 0.0⋅k

julia> I * q1
Quaternion{Float64}:
  + 0.866025 + 0.0⋅i + 0.5⋅j + 0.0⋅k
source
Base.:*Method
*(av₂::EulerAngleAxis, av₁::EulerAngleAxis) -> EulerAngleAxis

Compose av₁ followed by av₂.

Represent the result as an Euler angle and axis (see EulerAngleAxis). By convention, the output angle will always be in the range [0, π] [rad].

Require the vectors representing the axes in av₁ and av₂ to have unit length; this function neither verifies nor normalizes them.

Note

The element type of the output is float(promote_type(...)) of the element types of av₁ and av₂.

Examples

julia> av1 = EulerAngleAxis(deg2rad(45), [sqrt(2)/2, sqrt(2)/2, 0])
EulerAngleAxis{Float64}:
  Euler angle : 0.785398 rad  (45.0°)
  Euler axis  : [0.707107, 0.707107, 0.0]

julia> av2 = EulerAngleAxis(deg2rad(22.5), [sqrt(2)/2, sqrt(2)/2, 0])
EulerAngleAxis{Float64}:
  Euler angle : 0.392699 rad  (22.5°)
  Euler axis  : [0.707107, 0.707107, 0.0]

julia> av1 * av2
EulerAngleAxis{Float64}:
  Euler angle : 1.1781 rad  (67.5°)
  Euler axis  : [0.707107, 0.707107, 0.0]
source
Base.:+Method
+(c1::CRP, c2::CRP) -> CRP

Add the corresponding components of c1 and c2.

source
Base.:+Method
+(m1::MRP, m2::MRP) -> MRP

Add the corresponding components of m1 and m2.

source
Base.:+Method
+(qa::Quaternion, qb::Quaternion) -> Quaternion

Compute qa + qb.

If one of the operands is a UniformScaling:

+(u::UniformScaling, q::Quaternion)
+(q::Quaternion, u::UniformScaling)

then it is considered as the quaternion u.λ + 0 ⋅ i + 0 ⋅ j + 0 ⋅ k.

Examples

julia> q1 = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> q2 = Quaternion(0, cosd(45), 0, sind(45))
Quaternion{Float64}:
  + 0.0 + 0.707107⋅i + 0.0⋅j + 0.707107⋅k

julia> q1 + q2
Quaternion{Float64}:
  + 1.0 + 0.707107⋅i + 0.0⋅j + 0.707107⋅k

julia> q1 + I
Quaternion{Int64}:
  + 2 + 0⋅i + 0⋅j + 0⋅k
source
Base.:-Method
-(c::CRP) -> CRP
-(c1::CRP, c2::CRP) -> CRP

Negate c, or subtract c2 from c1 componentwise.

source
Base.:-Method
-(m::MRP) -> MRP
-(m1::MRP, m2::MRP) -> MRP

Negate m, or subtract m2 from m1 componentwise.

source
Base.:-Method
-(qa::Quaternion, qb::Quaternion) -> Quaternion

Compute qa - qb.

If one of the operands is a UniformScaling:

-(u::UniformScaling, q::Quaternion)
-(q::Quaternion, u::UniformScaling)

then it is considered as the quaternion u.λ + 0 ⋅ i + 0 ⋅ j + 0 ⋅ k.

Examples

julia> q1 = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> q2 = Quaternion(0, cosd(45), 0, sind(45))
Quaternion{Float64}:
  + 0.0 + 0.707107⋅i + 0.0⋅j + 0.707107⋅k

julia> q1 - q2
Quaternion{Float64}:
  + 1.0 - 0.707107⋅i + 0.0⋅j - 0.707107⋅k

julia> q1 - I
Quaternion{Int64}:
  + 0 + 0⋅i + 0⋅j + 0⋅k
source
Base.:-Method
-(q::Quaternion) -> Quaternion

Return the quaternion -q.

Examples

julia> q = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> -q
Quaternion{Int64}:
  - 1 + 0⋅i + 0⋅j + 0⋅k
source
Base.:/Method
/(c::CRP, λ::Number) -> CRP
/(c1::CRP, c2::CRP) -> CRP

Divide c by λ, or compose c1 with the inverse of c2.

source
Base.:/Method
/(m::MRP, λ::Number) -> MRP
/(m1::MRP, m2::MRP) -> MRP

Divide m by λ, or compose m1 with the inverse of m2.

source
Base.:/Method
/(λ::Number, q::Quaternion) -> Quaternion
/(q::Quaternion, λ::Number) -> Quaternion

Compute the division λ / q or q / λ, in which λ is a scalar.

Examples

julia> q = Quaternion(2, 0, 0, 0)
Quaternion{Int64}:
  + 2 + 0⋅i + 0⋅j + 0⋅k

julia> q / 2
Quaternion{Float64}:
  + 1.0 + 0.0⋅i + 0.0⋅j + 0.0⋅k
source
Base.:/Method
/(q1::Quaternion, q2::Quaternion) -> Quaternion

Compute q1 * inv(q2) (Hamilton product).

If one of the operands is a UniformScaling:

/(u::UniformScaling, q::Quaternion)
/(q::Quaternion, u::UniformScaling)

then it is considered as the quaternion u.λ + 0 ⋅ i + 0 ⋅ j + 0 ⋅ k.

Examples

julia> q1 = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> q2 = Quaternion(cosd(30), 0, sind(30), 0)
Quaternion{Float64}:
  + 0.866025 + 0.0⋅i + 0.5⋅j + 0.0⋅k

julia> q1 / q2
Quaternion{Float64}:
  + 0.707107 + 0.0⋅i + 0.707107⋅j + 0.0⋅k

julia> q1 / (2 * I)
Quaternion{Float64}:
  + 0.12941 + 0.0⋅i + 0.482963⋅j + 0.0⋅k
source
Base.:\Method
\(c1::CRP, c2::CRP) -> CRP

Compute the relative rotation from c1 to c2.

source
Base.:\Method
\(m1::MRP, m2::MRP) -> MRP

Compute the relative rotation from m1 to m2.

source
Base.:\Method
\(v::AbstractVector, q::Quaternion) -> Quaternion
\(q::Quaternion, v::AbstractVector) -> Quaternion

Compute the division qv \ q or q \ qv in which qv is a quaternion with real part 0 and vectorial/imaginary part v (Hamilton product).

Examples

julia> q = Quaternion(1, 0, 0, 0)
Quaternion{Int64}:
  + 1 + 0⋅i + 0⋅j + 0⋅k

julia> v = [0, cosd(60), sind(60)]
3-element Vector{Float64}:
 0.0
 0.5
 0.8660254037844386

julia> v \ q
Quaternion{Float64}:
  + 0.0 + 0.0⋅i - 0.5⋅j - 0.866025⋅k
source
Base.:\Method
\(q1::Quaternion, q2::Quaternion) -> Quaternion

Compute inv(q1) * q2.

If one of the operands is a UniformScaling:

\(u::UniformScaling, q::Quaternion)
\(q::Quaternion, u::UniformScaling)

then it is considered as the quaternion u.λ + 0 ⋅ i + 0 ⋅ j + 0 ⋅ k.

Examples

julia> q1 = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> q2 = Quaternion(cosd(30), 0, sind(30), 0)
Quaternion{Float64}:
  + 0.866025 + 0.0⋅i + 0.5⋅j + 0.0⋅k

julia> q2 \ q1
Quaternion{Float64}:
  + 0.707107 + 0.0⋅i + 0.707107⋅j + 0.0⋅k
source
Base.:∘Method
∘(R2::ReferenceFrameRotation, R1::ReferenceFrameRotation) -> ReferenceFrameRotation

Compose R1 followed by R2, converting R1 to the type of R2 before composition.

source
Base.:≈Method
≈(q1::Quaternion, q2::Quaternion; kwargs...) -> Bool

Compare corresponding components of q1 and q2 using isapprox.

Warning

The comparison is performed componentwise. Since the default atol is 0, a component that is (nearly) zero in one operand but exactly zero in the other makes the comparison fail. This differs from the norm-based semantics of isapprox for AbstractVector. Hence, pass atol explicitly when comparing rotations that may have near-zero components.

Keywords

  • kwargs...: Forwarded approximate-comparison keywords such as atol and rtol.
source
Base.conjMethod
conj(q::Quaternion) -> Quaternion

Compute the conjugate of the quaternion q:

q0 - q1.i - q2.j - q3.k

See also: inv

Examples

julia> q = Quaternion(1, cosd(75), 0, sind(75))
Quaternion{Float64}:
  + 1.0 + 0.258819⋅i + 0.0⋅j + 0.965926⋅k

julia> conj(q)
Quaternion{Float64}:
  + 1.0 - 0.258819⋅i - 0.0⋅j - 0.965926⋅k
source
Base.convertMethod
convert(::Type{CRP}, c::CRP) -> CRP
convert(::Type{CRP}, a::ReferenceFrameRotation) -> CRP
convert(::Type{CRP{T}}, a::ReferenceFrameRotation) where {T} -> CRP{T}

Convert rotation a to classical Rodrigues parameters, optionally changing its scalar type to T.

source
Base.convertMethod
convert(::Type{DCM}, a::ReferenceFrameRotation) -> DCM
convert(::Type{DCM{T}}, a::ReferenceFrameRotation) where {T} -> DCM{T}

Convert rotation a to a direction cosine matrix, optionally converting its scalar type to T.

source
Base.convertMethod
convert(::Type{EulerAngleAxis}, a::EulerAngleAxis) -> EulerAngleAxis
convert(::Type{EulerAngleAxis}, a::ReferenceFrameRotation) -> EulerAngleAxis
convert(::Type{EulerAngleAxis{T}}, a::EulerAngleAxis) where {T} -> EulerAngleAxis{T}
convert(
    ::Type{EulerAngleAxis{T}},
    a::ReferenceFrameRotation
) -> EulerAngleAxis{T}

Convert rotation a to an Euler angle-axis representation.

source
Base.convertMethod
convert(::Type{EulerAngles}, a::EulerAngles) -> EulerAngles
convert(::Type{EulerAngles}, a::ReferenceFrameRotation) -> EulerAngles
convert(::Type{EulerAngles{T}}, a::EulerAngles) where {T} -> EulerAngles{T}
convert(::Type{EulerAngles{T}}, a::ReferenceFrameRotation) where {T} -> EulerAngles{T}

Convert rotation a to Euler angles using the default :ZYX sequence, or preserve the sequence when a is already an EulerAngles value.

source
Base.convertMethod
convert(::Type{MRP}, m::MRP) -> MRP
convert(::Type{MRP}, a::ReferenceFrameRotation) -> MRP
convert(::Type{MRP{T}}, a::ReferenceFrameRotation) where {T} -> MRP{T}

Convert rotation a to modified Rodrigues parameters, optionally converting its scalar type to T.

source
Base.convertMethod
convert(::Type{Quaternion}, q::Quaternion) -> Quaternion
convert(::Type{Quaternion}, a::ReferenceFrameRotation) -> Quaternion
convert(::Type{Quaternion{T}}, a::ReferenceFrameRotation) where {T} -> Quaternion{T}

Convert rotation a to a scalar-first quaternion, optionally converting its scalar type to T.

source
Base.convertMethod
convert(::Type{CRP{T}}, c::CRP) where {T} -> CRP{T}

Convert CRP c to scalar type T.

source
Base.convertMethod
convert(::Type{MRP{T}}, m::MRP) where {T} -> MRP{T}

Convert MRP m to scalar type T.

source
Base.convertMethod
convert(::Type{Quaternion{T}}, q::Quaternion) where {T} -> Quaternion{T}

Convert quaternion q to scalar type T.

source
Base.copyMethod
copy(q::Quaternion{T}) where {T} -> Quaternion

Create a copy of the quaternion q.

source
Base.getindexMethod
getindex(dcm::DCM{T}, i::Int) where {T} -> T

Return an element of dcm using the indexing conventions provided by StaticArrays.

source
Base.imagMethod
imag(q::Quaternion{T}) -> SVector{3, T}

Return the vectorial or imaginary part of the quaternion q represented by a 3 × 1 vector of type SVector{3}.

See also: real, vect

Examples

julia> q = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> imag(q)
3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3):
 0.0
 0.9659258262890683
 0.0
source
Base.invMethod
inv(c::CRP) -> CRP

Compute the inverse of the CRP c.

source
Base.invMethod
inv(Θ::EulerAngles) -> EulerAngles

Return Euler angles representing the inverse rotation of Θ.

The rotation sequence of the result will be the inverse of the input. Hence, if the input rotation sequence is, for example, :XYZ, then the result will be represented using :ZYX.

Examples

julia> ea = EulerAngles(π / 3, π / 6,  2 / 3 * π, :ZYX)
EulerAngles{Float64}:
  R(Z) :  1.0472   rad  ( 60.0°)
  R(Y) :  0.523599 rad  ( 30.0°)
  R(X) :  2.0944   rad  ( 120.0°)

julia> inv(ea)
EulerAngles{Float64}:
  R(X) : -2.0944   rad  (-120.0°)
  R(Y) : -0.523599 rad  (-30.0°)
  R(Z) : -1.0472   rad  (-60.0°)
source
Base.invMethod
inv(m::MRP) -> MRP

Compute the inverse of the MRP m.

source
Base.invMethod
inv(q::Quaternion) -> Quaternion

Compute the inverse of the quaternion q:

conj(q)
───────
  |q|²

See also: conj

Examples

julia> q = Quaternion(1, 0, cosd(75), sind(75))
Quaternion{Float64}:
  + 1.0 + 0.0⋅i + 0.258819⋅j + 0.965926⋅k

julia> inv(q)
Quaternion{Float64}:
  + 0.5 - 0.0⋅i - 0.12941⋅j - 0.482963⋅k
source
Base.invMethod
inv(av::EulerAngleAxis) -> EulerAngleAxis

Return the inverse rotation of the Euler angle and axis av.

Return an Euler angle in the interval [0, π] [rad].

Examples

julia> av = EulerAngleAxis(deg2rad(20), [sqrt(2) / 2, 0, sqrt(2) / 2])
EulerAngleAxis{Float64}:
  Euler angle : 0.349066 rad  (20.0°)
  Euler axis  : [0.707107, 0.0, 0.707107]

julia> inv(av)
EulerAngleAxis{Float64}:
  Euler angle : 0.349066 rad  (20.0°)
  Euler axis  : [-0.707107, -0.0, -0.707107]

julia> av = EulerAngleAxis(deg2rad(-20), [sqrt(2) / 2, 0, sqrt(2) / 2])
EulerAngleAxis{Float64}:
  Euler angle : -0.349066 rad  (-20.0°)
  Euler axis  : [0.707107, 0.0, 0.707107]

julia> inv(av)
EulerAngleAxis{Float64}:
  Euler angle : 0.349066 rad  (20.0°)
  Euler axis  : [0.707107, 0.0, 0.707107]
source
Base.isapproxMethod
isapprox(c1::CRP, c2::CRP; kwargs...) -> Bool

Compare corresponding components of c1 and c2 using approximate equality.

Warning

The comparison is performed componentwise. Since the default atol is 0, a component that is (nearly) zero in one operand but exactly zero in the other makes the comparison fail. This differs from the norm-based semantics of isapprox for AbstractVector. Hence, pass atol explicitly when comparing rotations that may have near-zero components.

Keywords

  • kwargs...: Forwarded approximate-comparison keywords such as atol and rtol.
source
Base.isapproxMethod
isapprox(m1::MRP, m2::MRP; kwargs...) -> Bool

Compare corresponding components of m1 and m2 using approximate equality.

Warning

The comparison is performed componentwise. Since the default atol is 0, a component that is (nearly) zero in one operand but exactly zero in the other makes the comparison fail. This differs from the norm-based semantics of isapprox for AbstractVector. Hence, pass atol explicitly when comparing rotations that may have near-zero components.

Keywords

  • kwargs...: Forwarded approximate-comparison keywords such as atol and rtol.
source
Base.randMethod
rand(rng::AbstractRNG, ::Type{CRP}, dims::Dims) -> Array{CRP{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(rng::AbstractRNG, ::Type{DCM}, dims::Dims) -> Array{DCM{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(rng::AbstractRNG, ::Type{EulerAngleAxis}, dims::Dims) -> Array{EulerAngleAxis{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(rng::AbstractRNG, ::Type{EulerAngles}, dims::Dims) -> Array{EulerAngles{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(rng::AbstractRNG, ::Type{MRP}, dims::Dims) -> Array{MRP{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(rng::AbstractRNG, ::Type{Quaternion}, dims::Dims) -> Array{Quaternion{Float64}}

Sample an array of random rotations with the default Float64 scalar type, avoiding an abstract-eltype container.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: CRP} -> R

Sample a random CRP rotation using rng.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: DCM} -> R

Sample a uniformly distributed random rotation as a DCM using rng.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: EulerAngleAxis} -> R

Sample a uniformly distributed random Euler angle-axis rotation using rng.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: EulerAngles} -> R

Sample a random Euler-angle representation using rng.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: MRP} -> R

Sample a random MRP rotation using rng.

source
Base.randMethod
rand(
    rng::AbstractRNG,
    ::Random.SamplerType{R}
) where {R <: Quaternion} -> R

Sample a uniformly distributed random unit quaternion using rng.

source
Base.realMethod
real(q::Quaternion{T}) -> T

Return the real part of the quaternion q: q0.

See also: imag, vect

Examples

julia> q = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> real(q)
0.25881904510252074
source
Base.setindex!Method
setindex!(v::Vector{T}, c::CRP, I::UnitRange) where {T} -> Vector{T}

Write the three components of c into v at the positions in I, mutating v.

source
Base.setindex!Method
setindex!(v::Vector{T}, m::MRP, I::UnitRange) where {T} -> Vector{T}

Write the three components of m into v at the positions in I, mutating v.

source
Base.setindex!Method
setindex!(v::Vector{T}, q::Quaternion, I::UnitRange) where {T} -> Vector{T}

Write the four components of q into v at the positions in I, mutating v.

source
LinearAlgebra.normMethod
norm(q::Quaternion{T}) -> float(T)

Compute the Euclidean norm of the quaternion q:

√(q0² + q1² + q2² + q3²)

Examples

julia> q = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> norm(q)
1.0
source
ReferenceFrameRotations.angle_to_angleMethod
angle_to_angle(
    θ₁::Number,
    θ₂::Number,
    θ₃::Number,
    rot_seq_orig::Symbol,
    rot_seq_dest::Symbol
) -> EulerAngles
angle_to_angle(Θ::EulerAngles, rot_seq_dest::Symbol) -> EulerAngles

Convert the Euler angles θ₁, θ₂, and θ₃ [rad] with the rotation sequence rot_seq_orig to a new set of Euler angles with rotation sequence rot_seq_dest.

The input values can also be passed in the Θ structure (see EulerAngles).

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ.

Example

julia> angle_to_angle(-pi / 2, -pi / 3, -pi / 4, :ZYX, :XYZ)
EulerAngles{Float64}:
  R(X) : -1.0472   rad  (-60.0°)
  R(Y) :  0.785398 rad  ( 45.0°)
  R(Z) : -1.5708   rad  (-90.0°)

julia> angle_to_angle(-pi / 2, 0, 0, :ZYX, :XYZ)
EulerAngles{Float64}:
  R(X) :  0.0    rad  ( 0.0°)
  R(Y) :  0.0    rad  ( 0.0°)
  R(Z) : -1.5708 rad  (-90.0°)

julia> Θ = EulerAngles(1, 2, 3, :XYX)
EulerAngles{Int64}:
  R(X) :  1 rad  ( 57.2958°)
  R(Y) :  2 rad  ( 114.592°)
  R(X) :  3 rad  ( 171.887°)

julia> angle_to_angle(Θ, :ZYZ)
EulerAngles{Float64}:
  R(Z) : -2.70239 rad  (-154.836°)
  R(Y) :  1.46676 rad  ( 84.0393°)
  R(Z) : -1.05415 rad  (-60.3984°)
source
ReferenceFrameRotations.angle_to_angleaxisFunction
angle_to_angleaxis(
    θ₁::Number,
    θ₂::Number,
    θ₃::Number,
    rot_seq::Symbol = :ZYX
) -> EulerAngleAxis
angle_to_angleaxis(Θ::EulerAngles) -> EulerAngleAxis

Convert the Euler angles θ₁, θ₂, and θ₃ [rad] with the rotation sequence rot_seq to an Euler angle and axis representation.

Those values can also be passed inside the structure Θ (see EulerAngles).

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

Example

julia> angle_to_angleaxis(1, 0, 0, :XYZ)
EulerAngleAxis{Float64}:
  Euler angle : 1.0 rad  (57.2958°)
  Euler axis  : [1.0, 0.0, 0.0]

julia> Θ = EulerAngles(1, 1, 1, :XYZ);

julia> angle_to_angleaxis(Θ)
EulerAngleAxis{Float64}:
  Euler angle : 1.93909 rad  (111.102°)
  Euler axis  : [0.692363, 0.203145, 0.692363]
source
ReferenceFrameRotations.angle_to_crpFunction
angle_to_crp(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX) -> CRP
angle_to_crp(Θ::EulerAngles) -> CRP

Convert the Euler angles θ₁, θ₂, and θ₃ [rad] with the rotation sequence rot_seq to classical Rodrigues parameters.

Those values can also be passed inside the structure Θ (see EulerAngles).

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

source
ReferenceFrameRotations.angle_to_dcmMethod
angle_to_dcm(θ::Number, rot_seq::Symbol) -> DCM
angle_to_dcm(θ₁::Number, θ₂::Number, rot_seq::Symbol) -> DCM
angle_to_dcm(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX) -> DCM
angle_to_dcm(Θ::EulerAngles) -> DCM

Create a direction cosine matrix that performs rotations (θ₁, θ₂, and θ₃) about the coordinate axes specified in rot_seq.

The input values of the original Euler angles can also be passed inside the structure Θ (see EulerAngles).

The rotation sequence is defined by a Symbol specifying the rotation axes. The possible values depend on the number of rotations as follows:

  • 1 rotation (θ₁): :X, :Y, or :Z.
  • 2 rotations (θ₁, θ₂): :XY, :XZ, :YX, :YZ, :ZX, or :ZY.
  • 3 rotations (θ₁, θ₂, θ₃): :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, or :ZYZ

Remarks

This function assigns dcm = A3 * A2 * A1, where Ai is the DCM related to the i-th rotation, i ∈ [1, 2, 3]. If the i-th rotation is not specified, then Ai = I.

Example

julia> angle_to_dcm(pi / 2, :X)
DCM{Float64}:
 1.0   0.0          0.0
 0.0   6.12323e-17  1.0
 0.0  -1.0          6.12323e-17

julia> angle_to_dcm(pi / 5, pi / 7, :YZ)
DCM{Float64}:
  0.728899  0.433884  -0.529576
 -0.351019  0.900969   0.25503
  0.587785  0.0        0.809017

julia> angle_to_dcm(pi / 5, pi / 7, 0, :YZY)
DCM{Float64}:
  0.728899  0.433884  -0.529576
 -0.351019  0.900969   0.25503
  0.587785  0.0        0.809017

julia> dcm = angle_to_dcm(pi / 2, pi / 3, pi / 4, :ZYX)
DCM{Float64}:
  3.06162e-17  0.5       -0.866025
 -0.707107     0.612372   0.353553
  0.707107     0.612372   0.353553
source
ReferenceFrameRotations.angle_to_mrpFunction
angle_to_mrp(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX) -> MRP
angle_to_mrp(Θ::EulerAngles) -> MRP

Convert the Euler angles θ₁, θ₂, and θ₃ [rad] with the rotation sequence rot_seq to modified Rodrigues parameters.

Those values can also be passed inside the structure Θ (see EulerAngles).

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

source
ReferenceFrameRotations.angle_to_quatMethod
angle_to_quat(θ::Number, rot_seq::Symbol) -> Quaternion
angle_to_quat(θ₁::Number, θ₂::Number, rot_seq::Symbol) -> Quaternion
angle_to_quat(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX) -> Quaternion
angle_to_quat(Θ::EulerAngles) -> Quaternion

Create a quaternion that performs a set of rotations (θ₁, θ₂, θ₃) about the coordinate axes specified in rot_seq.

The input values can also be passed in the Θ structure (see EulerAngles).

The rotation sequence is defined by a Symbol specifying the rotation axes. The possible values depend on the number of rotations as follows:

  • 1 rotation (θ₁): :X, :Y, or :Z.
  • 2 rotations (θ₁, θ₂): :XY, :XZ, :YX, :YZ, :ZX, or :ZY.
  • 3 rotations (θ₁, θ₂, θ₃): :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, or :ZYZ
Note

The element type of the new quaternion is obtained by promoting the types of the input angles to a float.

Remarks

This function assigns q = q1 * q2 * q3, where qi is the quaternion related to the i-th rotation, i ∈ [1, 2, 3]. If the i-th rotation is not specified, then qi = Quaternion(I).

Example

julia> angle_to_quat(pi / 2, :X)
Quaternion{Float64}:
  + 0.707107 + 0.707107⋅i + 0.0⋅j + 0.0⋅k

julia> angle_to_quat(pi / 5, pi / 7, :YZ)
Quaternion{Float64}:
  + 0.927212 + 0.0687628⋅i + 0.301269⋅j + 0.21163⋅k

julia> angle_to_quat(pi / 5, pi / 7, 0, :YZX)
Quaternion{Float64}:
  + 0.927212 + 0.0687628⋅i + 0.301269⋅j + 0.21163⋅k

julia> angle_to_quat(pi / 2, pi / 3, pi / 4, :ZYX)
Quaternion{Float64}:
  + 0.701057 - 0.092296⋅i + 0.560986⋅j + 0.430459⋅k
source
ReferenceFrameRotations.angle_to_rotMethod
angle_to_rot(θ::Number, rot_seq::Symbol) -> DCM
angle_to_rot(θ₁::Number, θ₂::Number, rot_seq::Symbol) -> DCM
angle_to_rot(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol) -> DCM
angle_to_rot(::Type{DCM}, θ::Number, rot_seq::Symbol) -> DCM
angle_to_rot(::Type{Quaternion}, θ::Number, rot_seq::Symbol) -> Quaternion
angle_to_rot(::Type{DCM}, θ₁::Number, θ₂::Number, rot_seq::Symbol) -> DCM
angle_to_rot(::Type{Quaternion}, θ₁::Number, θ₂::Number, rot_seq::Symbol) -> Quaternion
angle_to_rot(::Type{DCM}, θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol) -> DCM
angle_to_rot(
    ::Type{Quaternion},
    θ₁::Number,
    θ₂::Number,
    θ₃::Number,
    rot_seq::Symbol
) -> Quaternion
angle_to_rot(Θ::EulerAngles) -> DCM
angle_to_rot(::Type{Union{DCM, Quaternion}}, Θ::EulerAngles) -> Union{DCM, Quaternion}

Create a rotation description of type T that performs rotations (θ₁, θ₂, and θ₃) about the coordinate axes specified in rot_seq.

The input values of the original Euler angles can also be passed inside the structure Θ (see EulerAngles).

The rotation sequence is defined by a Symbol specifying the rotation axes. The possible values depend on the number of rotations as follows:

  • 1 rotation (θ₁): :X, :Y, or :Z.
  • 2 rotations (θ₁, θ₂): :XY, :XZ, :YX, :YZ, :ZX, or :ZY.
  • 3 rotations (θ₁, θ₂, θ₃): :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, or :ZYZ

Example

julia> dcm = angle_to_rot(pi / 5, :Z)
DCM{Float64}:
  0.809017  0.587785  0.0
 -0.587785  0.809017  0.0
  0.0       0.0       1.0

julia> quat = angle_to_rot(Quaternion, pi / 5, :Z)
Quaternion{Float64}:
  + 0.951057 + 0.0⋅i + 0.0⋅j + 0.309017⋅k

julia> dcm = angle_to_rot(pi / 5, pi / 7, :YZ)
DCM{Float64}:
  0.728899  0.433884  -0.529576
 -0.351019  0.900969   0.25503
  0.587785  0.0        0.809017

julia> quat = angle_to_rot(Quaternion, pi / 5, pi / 7, :YZ)
Quaternion{Float64}:
  + 0.927212 + 0.0687628⋅i + 0.301269⋅j + 0.21163⋅k

julia> dcm = angle_to_rot(pi / 2, pi / 3, pi / 4, :ZYX)
DCM{Float64}:
  3.06162e-17  0.5       -0.866025
 -0.707107     0.612372   0.353553
  0.707107     0.612372   0.353553

julia> q = angle_to_rot(Quaternion, pi / 2, pi / 3, pi / 4, :ZYX)
Quaternion{Float64}:
  + 0.701057 - 0.092296⋅i + 0.560986⋅j + 0.430459⋅k
source
ReferenceFrameRotations.angleaxis_to_angleMethod
angleaxis_to_angle(θ::Number, v::AbstractVector, rot_seq::Symbol) -> EulerAngles
angleaxis_to_angle(av::EulerAngleAxis, rot_seq::Symbol) -> EulerAngles

Convert the Euler angle θ [rad] and Euler axis v to Euler angles with rotation sequence rot_seq.

Those values can also be passed inside the structure av (see EulerAngleAxis).

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. The rotation sequence is required for both calling forms.

Warning

It is expected that the vector v is unitary. However, no verification is performed inside the function. The user must handle this situation.

Example

julia> av = EulerAngleAxis(deg2rad(45), [1, 0, 0]);

julia> angleaxis_to_angle(av, :ZXY)
EulerAngles{Float64}:
  R(Z) :  0.0      rad  ( 0.0°)
  R(X) :  0.785398 rad  ( 45.0°)
  R(Y) :  0.0      rad  ( 0.0°)
source
ReferenceFrameRotations.angleaxis_to_crpMethod
angleaxis_to_crp(a::Number, v::AbstractVector) -> CRP
angleaxis_to_crp(av::EulerAngleAxis) -> CRP

Convert the Euler angle a [rad] and Euler axis v to classical Rodrigues parameters.

Those values can also be passed inside the structure av (see EulerAngleAxis).

Warning

It is expected that the vector v is unitary. However, no verification is performed inside the function. The user must handle this situation.

Example

julia> angleaxis_to_crp(pi / 2, [1, 0, 0])
CRP{Float64}:
  X : + 1.0
  Y : + 0.0
  Z : + 0.0
source
ReferenceFrameRotations.angleaxis_to_dcmMethod
angleaxis_to_dcm(a::Number, v::AbstractVector) -> DCM
angleaxis_to_dcm(av::EulerAngleAxis) -> DCM

Convert the Euler angle a [rad] and Euler axis v to a DCM.

Those values can also be passed inside the structure av (see EulerAngleAxis).

Warning

It is expected that the vector v is unitary. However, no verification is performed inside the function. The user must handle this situation.

Example

julia> v = [1, 1, 1];

julia> v /= norm(v);

julia> angleaxis_to_dcm(pi / 2, v)
DCM{Float64}:
  0.333333   0.910684  -0.244017
 -0.244017   0.333333   0.910684
  0.910684  -0.244017   0.333333

julia> ea = EulerAngleAxis(pi / 2, v);

julia> angleaxis_to_dcm(ea)
DCM{Float64}:
  0.333333   0.910684  -0.244017
 -0.244017   0.333333   0.910684
  0.910684  -0.244017   0.333333
source
ReferenceFrameRotations.angleaxis_to_mrpMethod
angleaxis_to_mrp(a::Number, v::AbstractVector) -> MRP
angleaxis_to_mrp(av::EulerAngleAxis) -> MRP

Convert the Euler angle a [rad] and Euler axis v to modified Rodrigues parameters.

Those values can also be passed inside the structure av (see EulerAngleAxis).

Warning

It is expected that the vector v is unitary. However, no verification is performed inside the function. The user must handle this situation.

Example

julia> angleaxis_to_mrp(pi / 2, [1, 0, 0])
MRP{Float64}:
  X : + 0.414214
  Y : + 0.0
  Z : + 0.0
source
ReferenceFrameRotations.angleaxis_to_quatMethod
angleaxis_to_quat(θ::Number, v::AbstractVector) -> Quaternion
angleaxis_to_quat(angleaxis::EulerAngleAxis) -> Quaternion

Convert the Euler angle θ [rad] and Euler axis v to a quaternion.

Those values can also be passed inside the structure angleaxis (see EulerAngleAxis).

Warning

It is expected that the vector v is unitary. However, no verification is performed inside the function. The user must handle this situation.

Example

julia> v = [1, 1, 1];

julia> v /= norm(v);

julia> angleaxis_to_quat(pi / 2, v)
Quaternion{Float64}:
  + 0.707107 + 0.408248⋅i + 0.408248⋅j + 0.408248⋅k
source
ReferenceFrameRotations.crp_to_angleFunction
crp_to_angle(c::CRP, rot_seq::Symbol = :ZYX) -> EulerAngles

Convert CRP c to Euler Angles (see EulerAngles) given a rotation sequence rot_seq.

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

Examples

julia> c = CRP(0.5, 0, 0)
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> crp_to_angle(c, :XYZ)
EulerAngles{Float64}:
  R(X) :  0.927295 rad  ( 53.1301°)
  R(Y) :  0.0      rad  ( 0.0°)
  R(Z) :  0.0      rad  ( 0.0°)
source
ReferenceFrameRotations.crp_to_angleaxisMethod
crp_to_angleaxis(c::CRP) -> EulerAngleAxis

Convert the CRP c to an Euler angle and axis representation (see EulerAngleAxis). By convention, the Euler angle will be kept between [0, π] rad.

Examples

julia> c = CRP(0.5, 0, 0)
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> crp_to_angleaxis(c)
EulerAngleAxis{Float64}:
  Euler angle : 0.927295 rad  (53.1301°)
  Euler axis  : [1.0, 0.0, 0.0]
source
ReferenceFrameRotations.crp_to_dcmMethod
crp_to_dcm(c::CRP) -> DCM

Convert the CRP c to a Direction Cosine Matrix (DCM).

Examples

julia> c = CRP(0.5, 0, 0)
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> crp_to_dcm(c)
DCM{Float64}:
 1.0   0.0  0.0
 0.0   0.6  0.8
 0.0  -0.8  0.6
source
ReferenceFrameRotations.crp_to_mrpMethod
crp_to_mrp(c::CRP) -> MRP

Convert CRP c to MRP.

Examples

julia> c = CRP(0.5, 0, 0)
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> crp_to_mrp(c)
MRP{Float64}:
  X : + 0.236068
  Y : + 0.0
  Z : + 0.0
source
ReferenceFrameRotations.crp_to_quatMethod
crp_to_quat(c::CRP) -> Quaternion

Convert CRP c to a quaternion.

Remarks

By convention, the real part of the quaternion will always be positive. Moreover, the function does not check if c is a valid classical Rodrigues parameter vector. This must be handled by the user.

Example

julia> c = CRP(0.5, 0, 0)
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> crp_to_quat(c)
Quaternion{Float64}:
  + 0.894427 + 0.447214⋅i + 0.0⋅j + 0.0⋅k
source
ReferenceFrameRotations.dcm_to_angleMethod
dcm_to_angle(dcm::DCM, rot_seq::Symbol = :ZYX) -> EulerAngles

Convert the dcm to Euler Angles (see EulerAngles) given a rotation sequence rot_seq.

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

Gimbal-lock and special cases

If the rotations are about three different axes, e.g. :XYZ, :ZYX, etc., then a second rotation of ±90 [°] yields gimbal lock. The rotations between the first and third axes have the same effect. In this case, the net rotation angle is assigned to the first rotation, and the angle of the third rotation is set to 0.

If the rotations are about two different axes, e.g. :XYX, :YXY, etc., then a rotation about the duplicated axis yields multiple representations. In this case, the entire angle is assigned to the first rotation and the third rotation is set to 0.

Example

julia> D = DCM([1. 0. 0.; 0. 0. -1; 0. -1 0.]);

julia> dcm_to_angle(D,:XYZ)
EulerAngles{Float64}:
  R(X) :  1.5708 rad  ( 90.0°)
  R(Y) :  0.0    rad  ( 0.0°)
  R(Z) :  0.0    rad  ( 0.0°)

julia> D = angle_to_dcm(1, -pi / 2, 2, :ZYX);

julia> dcm_to_angle(D, :ZYX)
EulerAngles{Float64}:
  R(Z) :  3.0    rad  ( 171.887°)
  R(Y) : -1.5708 rad  (-90.0°)
  R(X) :  0.0    rad  ( 0.0°)

julia> D = angle_to_dcm(1, :X) * angle_to_dcm(2, :X);

julia> dcm_to_angle(D, :XYX)
EulerAngles{Float64}:
  R(X) :  3.0 rad  ( 171.887°)
  R(Y) :  0.0 rad  ( 0.0°)
  R(X) :  0.0 rad  ( 0.0°)
source
ReferenceFrameRotations.dcm_to_angleaxisMethod
dcm_to_angleaxis(dcm::DCM) -> EulerAngleAxis

Convert the dcm to an Euler angle and axis representation.

Return an angle in the interval [0, π] [rad] by convention.

If dcm is the identity, the rotation angle is 0 and the Euler axis is undefined. In this case, return the zero vector [0, 0, 0] as the axis.

Note

If the rotation is a half turn (θ = π), then v and -v describe exactly the same rotation. Hence, the sign of the returned axis is arbitrary.

Remarks

The conversion is performed through the quaternion representation, which is numerically well conditioned for every rotation angle, including θ near π.

source
ReferenceFrameRotations.dcm_to_quatMethod
dcm_to_quat(dcm::DCM) -> Quaternion

Convert the dcm to a quaternion.

The type of the quaternion will be automatically selected by the constructor Quaternion to avoid InexactError.

Remarks

By convention, the real part of the quaternion will always be nonnegative (and is zero for exact half-turns). Moreover, the function does not check if dcm is a valid direction cosine matrix. This must be handled by the user.

This algorithm was obtained from [1].

Example

julia> dcm = angle_to_dcm(pi / 2, 0.0, 0.0, :XYZ);

julia> q = dcm_to_quat(dcm)
Quaternion{Float64}:
  + 0.707107 + 0.707107⋅i + 0.0⋅j + 0.0⋅k

References

  • [1]: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
source
ReferenceFrameRotations.dcrpMethod
dcrp(c::CRP, wba_b::AbstractVector) -> CRP

Compute the time derivative of CRP c that rotates reference frame a into alignment with the reference frame b in which the angular velocity of b with respect to a, and represented in b, is wba_b [rad/s] [1].

Example

julia> c = CRP(0.0, 0.0, 0.0)
CRP{Float64}:
  X : + 0.0
  Y : + 0.0
  Z : + 0.0

julia> dcrp(c, [1.0, 0.0, 0.0])
CRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

References

  • [1] Schaub, H.; Junkins, J. L (1996). Stereographic Orientation Parameters for Attitude Dynamics: A Generalization of the Rodrigues Parameters. In: Journal of the Astronautical Sciences, Vol. 44, No. 1, pp. 1 – 19.
source
ReferenceFrameRotations.ddcmMethod
ddcm(Dba::DCM, wba_b::AbstractArray) -> SMatrix{3, 3}

Compute the time derivative of Dba that rotates reference frame a into alignment with the reference frame b in which the angular velocity of b with respect to a, and represented in b, is wba_b [rad/s].

Example

julia> D = DCM(1.0I);

julia> ddcm(D, [1, 0, 0])
3×3 StaticArraysCore.SMatrix{3, 3, Float64, 9} with indices SOneTo(3)×SOneTo(3):
 0.0   0.0  0.0
 0.0   0.0  1.0
 0.0  -1.0  0.0
source
ReferenceFrameRotations.dmrpMethod
dmrp(m::MRP, wba_b::AbstractVector) -> MRP

Compute the time derivative of MRP m that rotates reference frame a into alignment with the reference frame b in which the angular velocity of b with respect to a, and represented in b, is wba_b [rad/s] [1].

Example

julia> m = MRP(0.0, 0.0, 0.0)
MRP{Float64}:
  X : + 0.0
  Y : + 0.0
  Z : + 0.0

julia> dmrp(m, [1.0, 0.0, 0.0])
MRP{Float64}:
  X : + 0.25
  Y : + 0.0
  Z : + 0.0

References

  • [1] Schaub, H.; Junkins, J. L (1996). Stereographic Orientation Parameters for Attitude Dynamics: A Generalization of the Rodrigues Parameters. In: Journal of the Astronautical Sciences, Vol. 44, No. 1, pp. 1 – 19.
source
ReferenceFrameRotations.dquatMethod
dquat(qba::Quaternion, wba_b::AbstractVector) -> Quaternion

Compute the time derivative of quaternion qba that rotates reference frame a into alignment to the reference frame b in which the angular velocity of b with respect to a, and represented in b, is wba_b [rad/s].

Examples

julia> q = Quaternion(1.0I);

julia> dquat(q,[1;0;0])
Quaternion{Float64}:
  - 0.0 + 0.5⋅i + 0.0⋅j + 0.0⋅k
source
ReferenceFrameRotations.inv_rotationMethod
inv_rotation(R::ReferenceFrameRotation) -> ReferenceFrameRotation

Compute the inverse rotation of R, which can be:

  • A direction cosine matrix (DCM);
  • An Euler angle and axis (EulerAngleAxis);
  • A set of Euler angles (EulerAngles);
  • A quaternion (Quaternion);
  • Classical Rodrigues parameters (CRP); or
  • Modified Rodrigues parameters (MRP).

The output will have the same type as R, except that an EulerAngleAxis is promoted to a floating-point element type.

Note

If R is a DCM, then its transpose is computed instead of its inverse to reduce the computational burden. The two are equal if the DCM is orthonormal. This must be verified by the user.

Note

If R is a quaternion, then its conjugate is computed instead of its inverse to reduce the computational burden. The two are equal if the quaternion has unit norm. This must be verified by the user.

Example

julia> D = angle_to_dcm(pi / 3, pi / 4, pi / 5, :ZYX);

julia> inv_rotation(D)
DCM{Float64}:
  0.353553  -0.492816  0.795068
  0.612372   0.764452  0.201527
 -0.707107   0.415627  0.572061

julia> ea = EulerAngleAxis(30 * pi / 180, [1, 0, 0]);

julia> inv_rotation(ea)
EulerAngleAxis{Float64}:
  Euler angle : 0.523599 rad  (30.0°)
  Euler axis  : [-1.0, -0.0, -0.0]

julia> Θ = EulerAngles(-pi / 3, -pi / 2, -pi, :YXZ);

julia> inv_rotation(Θ)
EulerAngles{Float64}:
  R(Z) :  3.14159 rad  ( 180.0°)
  R(X) :  1.5708  rad  ( 90.0°)
  R(Y) :  1.0472  rad  ( 60.0°)

julia> q = angle_to_quat(pi / 3, pi / 4, pi / 5, :ZYX);

julia> inv_rotation(q)
Quaternion{Float64}:
  + 0.820071 - 0.0652687⋅i - 0.45794⋅j - 0.336918⋅k
source
ReferenceFrameRotations.mrp_to_angleFunction
mrp_to_angle(m::MRP, rot_seq::Symbol = :ZYX) -> EulerAngles

Convert MRP m to Euler Angles (see EulerAngles) given a rotation sequence rot_seq.

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

Examples

julia> m = MRP(0.5, 0, 0)
MRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> mrp_to_angle(m, :XYZ)
EulerAngles{Float64}:
  R(X) :  1.85459 rad  ( 106.26°)
  R(Y) :  0.0     rad  ( 0.0°)
  R(Z) :  0.0     rad  ( 0.0°)
source
ReferenceFrameRotations.mrp_to_angleaxisMethod
mrp_to_angleaxis(m::MRP) -> EulerAngleAxis

Convert the MRP m to an Euler angle and axis representation (see EulerAngleAxis). By convention, the Euler angle will be kept between [0, π] rad.

Examples

julia> m = MRP(0.5, 0, 0)
MRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> mrp_to_angleaxis(m)
EulerAngleAxis{Float64}:
  Euler angle : 1.85459 rad  (106.26°)
  Euler axis  : [1.0, 0.0, 0.0]
source
ReferenceFrameRotations.mrp_to_crpMethod
mrp_to_crp(m::MRP) -> CRP

Convert MRP m to CRP.

Examples

julia> m = MRP(0.5, 0, 0)
MRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> mrp_to_crp(m)
CRP{Float64}:
  X : + 1.33333
  Y : + 0.0
  Z : + 0.0
source
ReferenceFrameRotations.mrp_to_dcmMethod
mrp_to_dcm(m::MRP) -> DCM

Convert MRP m to a Direction Cosine Matrix (DCM).

Examples

julia> m = MRP(0.5, 0, 0)
MRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> mrp_to_dcm(m)
DCM{Float64}:
 1.0   0.0    0.0
 0.0  -0.28   0.96
 0.0  -0.96  -0.28
source
ReferenceFrameRotations.mrp_to_quatMethod
mrp_to_quat(m::MRP) -> Quaternion

Convert MRP m to a quaternion.

Remarks

The real part of the resulting quaternion is positive if |m| < 1 and negative if |m| > 1 (the shadow MRP set). Moreover, the function does not check if m is a valid modified Rodrigues parameter vector. This must be handled by the user.

Example

julia> m = MRP(0.5, 0, 0)
MRP{Float64}:
  X : + 0.5
  Y : + 0.0
  Z : + 0.0

julia> mrp_to_quat(m)
Quaternion{Float64}:
  + 0.6 + 0.8⋅i + 0.0⋅j + 0.0⋅k
source
ReferenceFrameRotations.orthonormalizeMethod
orthonormalize(dcm::DCM) -> DCM

Perform the Gram-Schmidt orthonormalization process on the dcm and return the new matrix.

Warning

This function does not check if the columns of the input matrix span a three-dimensional space. If not, then the returned matrix will contain NaNs. Notice, however, that such input matrix is not a valid direction cosine matrix.

Warning

The Gram-Schmidt process preserves the handedness of the input matrix. Hence, this function does not restore det(dcm) == +1: if the input matrix is improper, the returned matrix is orthonormal but also improper.

Example

julia> D = DCM(3I);

julia> orthonormalize(D)
DCM{Float64}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0
source
ReferenceFrameRotations.quat_to_angleFunction
quat_to_angle(q::Quaternion, rot_seq::Symbol = :ZYX) -> EulerAngles

Convert the quaternion q to Euler Angles (see EulerAngles) given a rotation sequence rot_seq.

The rotation sequence is defined by a :Symbol. The possible values are: :XYX, :XYZ, :XZX, :XZY, :YXY, :YXZ, :YZX, :YZY, :ZXY, :ZXZ, :ZYX, and :ZYZ. If no value is specified, it defaults to :ZYX.

Examples

julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);

julia> quat_to_angle(q, :XYZ)
EulerAngles{Float64}:
  R(X) :  0.785398 rad  ( 45.0°)
  R(Y) :  0.0      rad  ( 0.0°)
  R(Z) :  0.0      rad  ( 0.0°)
source
ReferenceFrameRotations.quat_to_angleaxisMethod
quat_to_angleaxis(q::Quaternion) -> EulerAngleAxis

Convert the quaternion q to an Euler angle and axis representation (see EulerAngleAxis). By convention, keep the Euler angle between [0, π] [rad].

If q is the identity rotation, the Euler axis is undefined. In this case, return the zero vector [0, 0, 0] as the axis.

Note

If the rotation is a half turn (θ = π), then v and -v describe exactly the same rotation. Hence, the sign of the returned axis is arbitrary.

Remarks

This function will not fail if the quaternion norm is not 1. However, the meaning of the results will not be defined, because the input quaternion does not represent a 3D rotation. The user must handle such situations.

Examples

julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);

julia> quat_to_angleaxis(q)
EulerAngleAxis{Float64}:
  Euler angle : 0.785398 rad  (45.0°)
  Euler axis  : [1.0, 0.0, 0.0]
source
ReferenceFrameRotations.quat_to_dcmMethod
quat_to_dcm(q::Quaternion) -> DCM

Convert the quaternion q to a Direction Cosine Matrix (DCM).

Examples

julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);

julia> quat_to_dcm(q)
DCM{Float64}:
 1.0   0.0       0.0
 0.0   0.707107  0.707107
 0.0  -0.707107  0.707107
source
ReferenceFrameRotations.shadow_rotationMethod
shadow_rotation(m::MRP) -> MRP

Return the shadow rotation -m / |m|² of the MRP m. It represents the same rotation as m, and its norm is the reciprocal of the norm of m. Hence, a unit MRP maps to its antipode.

The shadow set is undefined for the zero MRP, for which this function throws a DomainError. For nonzero inputs, scalar types whose reciprocal remains in the same type, such as Rational and BigFloat, are preserved.

source
ReferenceFrameRotations.smallangle_to_dcmMethod
smallangle_to_dcm(θx::Number, θy::Number, θz::Number; kwargs...) -> DCM

Create a direction cosine matrix from three small rotations of angles θx, θy, and θz [rad] about the axes X, Y, and Z, respectively.

If the keyword normalize is true, the matrix will be normalized using the function orthonormalize.

Keywords

  • normalize::Bool: Orthonormalize the resulting matrix. (Default: true)

Example

julia> smallangle_to_dcm(+0.01, -0.01, +0.01)
DCM{Float64}:
  0.9999     0.00989903  0.010098
 -0.009999   0.999901    0.00989802
 -0.009999  -0.009998    0.9999

julia> smallangle_to_dcm(+0.01, -0.01, +0.01; normalize = false)
DCM{Float64}:
  1.0    0.01  0.01
 -0.01   1.0   0.01
 -0.01  -0.01  1.0
source
ReferenceFrameRotations.smallangle_to_quatMethod
smallangle_to_quat(θx::Number, θy::Number, θz::Number) -> Quaternion

Create a quaternion from three small rotations of angles θx, θy, and θz [rad] about the axes X, Y, and Z, respectively.

Note

The quaternion is always normalized.

Example

julia> smallangle_to_quat(+0.01, -0.01, +0.01)
Quaternion{Float64}:
  + 0.999963 + 0.00499981⋅i - 0.00499981⋅j + 0.00499981⋅k
source
ReferenceFrameRotations.smallangle_to_rotMethod
smallangle_to_rot(θx::Number, θy::Number, θz::Number; kwargs...) -> DCM
smallangle_to_rot(::Type{DCM}, θx::Number, θy::Number, θz::Number; kwargs...) -> DCM
smallangle_to_rot(::Type{Quaternion}, θx::Number, θy::Number, θz::Number) -> Quaternion

Create a rotation description of type T from three small rotations of angles θx, θy, and θz [rad] about the axes X, Y, and Z, respectively.

The type T of the rotation description can be DCM or Quaternion. If the type T is not specified, it defaults to DCM.

If T is DCM, orthonormalize the resulting matrix using orthonormalize function if the keyword normalize is true.

Keywords

  • normalize::Bool: Orthonormalize a DCM result when true. (Default: true)

Example

julia> dcm = smallangle_to_rot(+0.01, -0.01, +0.01)
DCM{Float64}:
  0.9999     0.00989903  0.010098
 -0.009999   0.999901    0.00989802
 -0.009999  -0.009998    0.9999

julia> dcm = smallangle_to_rot(+0.01, -0.01, +0.01; normalize = false)
DCM{Float64}:
  1.0    0.01  0.01
 -0.01   1.0   0.01
 -0.01  -0.01  1.0

julia> q = smallangle_to_rot(Quaternion, +0.01, -0.01, +0.01)
Quaternion{Float64}:
  + 0.999963 + 0.00499981⋅i - 0.00499981⋅j + 0.00499981⋅k
source
ReferenceFrameRotations.vectMethod
vect(q::Quaternion{T}) -> SVector{3, T}

Return the vectorial or imaginary part of the quaternion q represented by a 3 × 1 vector of type SVector{3, T}.

See also: imag, real

Examples

julia> q = Quaternion(cosd(75), 0, sind(75), 0)
Quaternion{Float64}:
  + 0.258819 + 0.0⋅i + 0.965926⋅j + 0.0⋅k

julia> vect(q)
3-element StaticArraysCore.SVector{3, Float64} with indices SOneTo(3):
 0.0
 0.9659258262890683
 0.0
source