Library
Documentation for ReferenceFrameRotations.jl
.
ReferenceFrameRotations.DCM
— Type.The Direction Cosine Matrix of type T
is a SMatrix{3,3,T,9}
, which is a 3x3 static matrix of type T
.
struct EulerAngleAxis{T}
The definition of Euler Angle and Axis to represent a 3D rotation.
Fields
a
: The Euler angle [rad].v
: The unitary vector aligned with the Euler axis.
Constructor
function EulerAngleAxis(a::T1, v::AbstractVector{T2}) where {T1,T2}
Create an Euler Angle and Axis representation structure with angle a
[rad] and vector v
. Notice that the vector v
will not be normalized. The type of the returned structure will be selected according to the input types.
struct EulerAngles{T}
The definition of Euler Angles, which is composed of three angles a1
, a2
, and a3
together with a rotation sequence rot_seq
. The latter is provided by a symbol with three characters, each one indicating the rotation axis of the corresponding angle (for example, :ZYX
). The valid values for rot_seq
are:
:XYX
,:XYZ
,:XZX
,:XZY
,:YXY
,:YXZ
,:YZX
,:YZY
,:ZXY
,:ZXZ
,:ZYX
, andZYZ
.
Constructor
function EulerAngles(a1::T1, a2::T2, a3::T3, rot_seq::Symbol = :ZYX) where {T1,T2,T3}
Create a new instance of EulerAngles
with the angles a1
, a2
, and a3
and the rotation sequence rot_seq
. The type will be inferred from T1
, T2
, and T3
. If rot_seq
is not provided, then it defaults to :ZYX
.
struct Quaternion{T}
The definition of the quaternion. It has four values of type T
. The quaternion representation is:
q0 + q1.i + q2.j + q3.k
ReferenceFrameRotations.Quaternion
— Method.function Quaternion(v::AbstractVector)
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
ReferenceFrameRotations.Quaternion
— Method.function Quaternion(r::Number, v::AbstractVector)
Create a quaternion with real part r
and vectorial or imaginary part v
:
r + v[1].i + v[2].j + v[3].k
ReferenceFrameRotations.Quaternion
— Method.function Quaternion(q0::T0, q1::T1, q2::T2, q3::T3) where {T0,T1,T2,T3}
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.
ReferenceFrameRotations.Quaternion
— Method.function Quaternion(::UniformScaling,::Quaternion{T}) where T
Create an identity quaternion of type T
:
T(1) + T(0).i + T(0).j + T(0).k
ReferenceFrameRotations.Quaternion
— Method.function Quaternion(u::UniformScaling{T}) where T
function Quaternion{T}(u::UniformScaling) where T
Create the quaternion u.λ + 0.i + 0.j + 0.k
.
Base.inv
— Method.function inv(Θ::EulerAngles)
Return the Euler angles that represent the inverse rotation of Θ
. Notice that 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
.
Base.inv
— Method.@inline function inv(q::Quaternion)
Compute the inverse of the quaternion q
:
conj(q)
-------
|q|²
Base.inv
— Method.@inline function inv(ea::EulerAngleAxis)
Compute the inverse rotation of ea
. The Euler angle returned by this function will always be in the interval [0, π].
LinearAlgebra.norm
— Method.@inline function norm(q::Quaternion)
Compute the Euclidean norm of the quaternion q
:
sqrt(q0² + q1² + q2² + q3²)
ReferenceFrameRotations.angle_to_angle
— Method.@inline function angle_to_angle(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq_orig::Symbol, rot_seq_dest::Symbol)
@inline function angle_to_angle(Θ::EulerAngles, rot_seq_dest::Symbol)
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 of the origin Euler angles 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, then it defaults to :ZYX
.
Example
julia> angle_to_angle(-pi/2, -pi/3, -pi/4, :ZYX, :XYZ)
EulerAngles{Float64}:
R(X): -1.0472 rad ( -60.0000 deg)
R(Y): 0.7854 rad ( 45.0000 deg)
R(Z): -1.5708 rad ( -90.0000 deg)
julia> angle_to_angle(-pi/2, 0, 0, :ZYX, :XYZ)
EulerAngles{Float64}:
R(X): 0.0000 rad ( 0.0000 deg)
R(Y): 0.0000 rad ( 0.0000 deg)
R(Z): -1.5708 rad ( -90.0000 deg)
julia> Θ = EulerAngles(1,2,3,:XYX)
EulerAngles{Int64}:
R(X): 1.0000 rad ( 57.2958 deg)
R(Y): 2.0000 rad ( 114.5916 deg)
R(X): 3.0000 rad ( 171.8873 deg)
julia> angle_to_angle(Θ,:ZYZ)
EulerAngles{Float64}:
R(Z): -2.7024 rad (-154.8356 deg)
R(Y): 1.4668 rad ( 84.0393 deg)
R(Z): -1.0542 rad ( -60.3984 deg)
ReferenceFrameRotations.angle_to_angleaxis
— Function.@inline function angle_to_angleaxis(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX)
@inline function angle_to_angleaxis(Θ::EulerAngles)
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, then it defaults to :ZYX
.
Example
julia> angle_to_angleaxis(1,0,0,:XYZ)
EulerAngleAxis{Float64}:
Euler angle: 1.0000 rad ( 57.2958 deg)
Euler axis: [ 1.0000, 0.0000, 0.0000]
julia> Θ = EulerAngles(1,1,1,:XYZ);
julia> angle_to_angleaxis(Θ)
EulerAngleAxis{Float64}:
Euler angle: 1.9391 rad (111.1015 deg)
Euler axis: [ 0.6924, 0.2031, 0.6924]
ReferenceFrameRotations.angle_to_dcm
— Function.function angle_to_dcm(θ₁::Number, θ₂::Number, θ₃::Number, rot_seq::Symbol = :ZYX)
Convert the Euler angles θ₁
, θ₂
, and θ₃
[rad] with the rotation sequence rot_seq
to a direction cosine matrix.
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, then it defaults to :ZYX
.
Remarks
This function assigns dcm = A3 * A2 * A1
in which Ai
is the DCM related with the i-th rotation, i Є [1,2,3]
.
Example
dcm = angle_to_dcm(pi/2, pi/3, pi/4, :ZYX)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
3.06162e-17 0.5 -0.866025
-0.707107 0.612372 0.353553
0.707107 0.612372 0.353553
ReferenceFrameRotations.angle_to_dcm
— Method.function angle_to_dcm(Θ::EulerAngles)
Convert the Euler angles Θ
(see EulerAngles
) to a direction cosine matrix.
Returns
The direction cosine matrix.
Remarks
This function assigns dcm = A3 * A2 * A1
in which Ai
is the DCM related with the i-th rotation, i Є [1,2,3]
.
Example
julia> angle_to_dcm(EulerAngles(pi/2, pi/3, pi/4, :ZYX))
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
3.06162e-17 0.5 -0.866025
-0.707107 0.612372 0.353553
0.707107 0.612372 0.353553
ReferenceFrameRotations.angle_to_quat
— Method.function angle_to_quat(eulerang::EulerAngles)
Convert the Euler angles eulerang
(see EulerAngles
) to a quaternion.
Remarks
This function assigns q = q1 * q2 * q3
in which qi
is the quaternion related with the i-th rotation, i Є [1,2,3]
.
Example
julia> angle_to_quat(pi/2, pi/3, pi/4, :ZYX)
Quaternion{Float64}:
+ 0.7010573846499779 - 0.09229595564125714.i + 0.5609855267969309.j + 0.43045933457687935.k
ReferenceFrameRotations.angle_to_quat
— Method.function angle_to_quat(θ₁::T1, θ₂::T2, θ₃::T3, rot_seq::Symbol = :ZYX) where {T1<:Number, T2<:Number, T3<:Number}
Convert the Euler angles θ₁
, θ₂
, and θ₃
[rad] with the rotation sequence rot_seq
to a quaternion.
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, then it defaults to :ZYX
.
Remarks
This function assigns q = q1 * q2 * q3
in which qi
is the quaternion related with the i-th rotation, i Є [1,2,3]
.
Example
julia> angle_to_quat(pi/2, pi/3, pi/4, :ZYX)
Quaternion{Float64}:
+ 0.7010573846499779 - 0.09229595564125714.i + 0.5609855267969309.j + 0.43045933457687935.k
ReferenceFrameRotations.angle_to_rot
— Method.@inline angle_to_rot([T,] Θ::EulerAngles)
Convert the Euler angles Θ
(see EulerAngles
) to a rotation description of type T
, which can be DCM
or Quaternion
. If the type T
is not specified, then it defaults to DCM
.
Example
julia> dcm = angle_to_rot(EulerAngles(pi/2, pi/3, pi/4, :ZYX))
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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,EulerAngles(pi/2, pi/3, pi/4, :ZYX))
Quaternion{Float64}:
+ 0.7010573846499779 - 0.09229595564125714.i + 0.5609855267969309.j +
0.43045933457687935.k
ReferenceFrameRotations.angle_to_rot
— Method.@inline angle_to_rot([T,] θx::Number, θy::Number, θz::Number, rot_seq::Symbol)
Convert the Euler angles Θx
, Θy
, and Θz
[rad] with the rotation sequence rot_seq
to a rotation description of type T
, which can be DCM
or Quaternion
. If the type T
is not specified, then it defaults to DCM
.
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, then it defaults to :ZYX
.
Example
julia> dcm = angle_to_rot(pi/2, pi/3, pi/4, :ZYX)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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.7010573846499779 - 0.09229595564125714.i + 0.5609855267969309.j + 0.43045933457687935.k
@inline function angleaxis_to_angle(θ::Number, v::AbstractVector, rot_seq::Symbol)
@inline function angleaxis_to_angle(ea::EulerAngleAxis, rot_seq::Symbol)
Convert the Euler angle θ
[rad] and Euler axis v
, which must be a unit vector, to Euler angles with rotation sequence rot_seq
. Those values can also be passed inside the structure ea
(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
. If no value is specified, then it defaults to :ZYX
.
Example
julia> ea = EulerAngleAxis(45*pi/180, [1;0;0]);
julia> angleaxis_to_angles(ea, :ZXY)
EulerAngles{Float64}:
R(Z): 0.0000 rad ( 0.0000 deg)
R(X): 0.7854 rad ( 45.0000 deg)
R(Y): 0.0000 rad ( 0.0000 deg)
ReferenceFrameRotations.angleaxis_to_dcm
— Method.@inline function angleaxis_to_dcm(a::Number, v::AbstractVector)
@inline function angleaxis_to_dcm(ea::EulerAngleAxis)
Convert the Euler angle a
[rad] and Euler axis v
, which must be a unit vector to a DCM. Those values can also be passed inside the structure ea
(see EulerAngleAxis
).
Remarks
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)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
0.333333 0.910684 -0.244017
-0.244017 0.333333 0.910684
0.910684 -0.244017 0.333333
function angleaxis_to_quat(angleaxis::EulerAngleAxis)
Convert a Euler angle and Euler axis angleaxis
(see EulerAngleAxis
) to a quaternion.
Remarks
It is expected that the vector angleaxis.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(EulerAngleAxis(pi/2,v))
Quaternion{Float64}:
+ 0.7071067811865476 + 0.408248290463863.i + 0.408248290463863.j + 0.408248290463863.k
function angleaxis_to_quat(θ::Number, v::AbstractVector)
Convert the Euler angle θ
[rad] and Euler axis v
, which must be a unit vector, to a quaternion.
Remarks
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.7071067811865476 + 0.408248290463863.i + 0.408248290463863.j + 0.408248290463863.k
ReferenceFrameRotations.compose_rotation
— Method.@inline function compose_rotation(R1, [, R2, R3, R4, R5, ...])
Compute a composed rotation using the rotations R1
, R2
, R3
, R4
, ..., in the following order:
First rotation
|
|
R1 => R2 => R3 => R4 => ...
|
|
Second rotation
The rotations can be described by:
- A direction cosina matrix (
DCM
); - An Euler angle and axis (
EulerAngleAxis
); - A set of Euler anlges (
EulerAngles
); or - A quaternion (
Quaternion
).
Notice, however, that all rotations must be of the same type (DCM or quaternion).
The output will have the same type as the inputs.
Example
julia> D1 = angle_to_dcm(+pi/3,+pi/4,+pi/5,:ZYX);
julia> D2 = angle_to_dcm(-pi/5,-pi/4,-pi/3,:XYZ);
julia> compose_rotation(D1,D2)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
1.0 0.0 5.55112e-17
0.0 1.0 5.55112e-17
5.55112e-17 5.55112e-17 1.0
julia> ea1 = EulerAngleAxis(30*pi/180, [0;1;0]);
julia> ea2 = EulerAngleAxis(45*pi/180, [0;1;0]);
julia> compose_rotation(ea1,ea2)
EulerAngleAxis{Float64}:
Euler angle: 1.3090 rad ( 75.0000 deg)
Euler axis: [ 0.0000, 1.0000, 0.0000]
julia> Θ1 = EulerAngles(1,2,3,:ZYX);
julia> Θ2 = EulerAngles(-3,-2,-1,:XYZ);
julia> compose_rotation(Θ1, Θ2)
EulerAngles{Float64}:
R(X): -0.0000 rad ( -0.0000 deg)
R(Y): 0.0000 rad ( 0.0000 deg)
R(Z): -0.0000 rad ( -0.0000 deg)
julia> q1 = angle_to_quat(+pi/3,+pi/4,+pi/5,:ZYX);
julia> q2 = angle_to_quat(-pi/5,-pi/4,-pi/3,:XYZ);
julia> compose_rotation(q1,q2)
Quaternion{Float64}:
+ 1.0 + 0.0.i + 2.0816681711721685e-17.j + 5.551115123125783e-17.k
ReferenceFrameRotations.create_rotation_matrix
— Function.function create_rotation_matrix(angle::Number, axis::Symbol = :X)
Compute a rotation matrix that rotates a coordinate frame about the axis axis
by the angle angle
. The axis
must be one of the following symbols: :X
, :Y
, or :Z
.
Example
julia> create_rotation_matrix(pi/2, :X)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
1.0 0.0 0.0
0.0 6.12323e-17 1.0
0.0 -1.0 6.12323e-17
ReferenceFrameRotations.dcm_to_angle
— Method.function dcm_to_angle(dcm::DCM, rot_seq::Symbol=:ZYX)
Convert the DCM 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, then 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 a gimbal-lock. This means that 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.0000 deg)
R(Y): 0.0000 rad ( 0.0000 deg)
R(Z): 0.0000 rad ( 0.0000 deg)
julia> D = angle_to_dcm(1, -pi/2, 2, :ZYX);
julia> dcm_to_angle(D,:ZYX)
EulerAngles{Float64}:
R(Z): 3.0000 rad ( 171.8873 deg)
R(Y): -1.5708 rad ( -90.0000 deg)
R(X): 0.0000 rad ( 0.0000 deg)
julia> D = create_rotation_matrix(1,:X)*create_rotation_matrix(2,:X);
julia> dcm_to_angle(D,:XYX)
EulerAngles{Float64}:
R(X): 3.0000 rad ( 171.8873 deg)
R(Y): 0.0000 rad ( 0.0000 deg)
R(X): 0.0000 rad ( 0.0000 deg)
ReferenceFrameRotations.dcm_to_angleaxis
— Method.function dcm_to_angleaxis(dcm::DCM{T}) where T<:Number
Convert the DCM dcm
to an Euler angle and axis representation. By convention, the returned Euler angle will always be in the interval [0, π].
ReferenceFrameRotations.dcm_to_quat
— Method.function dcm_to_quat(dcm::DCM)
Convert the DCM 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 positive. Moreover, the function does not check if dcm
is a valid direction cosine matrix. This must be handle by the user.
This algorithm was obtained from:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
Example
julia> dcm = angle_to_dcm(pi/2,0.0,0.0,:XYZ);
julia> q = dcm_to_quat(dcm)
Quaternion{Float64}:
+ 0.7071067811865476 + 0.7071067811865475.i + 0.0.j + 0.0.k
ReferenceFrameRotations.ddcm
— Method.function ddcm(Dba::DCM, wba_b::AbstractArray)
Compute the time-derivative of the DCM dcm
that rotates a 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
.
Returns
The time-derivative of the DCM Dba
(3x3 matrix of type SMatrix{3,3}
).
Example
julia> D = DCM(Matrix{Float64}(I,3,3));
julia> ddcm(D,[1;0;0])
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
0.0 0.0 0.0
0.0 0.0 1.0
0.0 -1.0 0.0
ReferenceFrameRotations.dquat
— Method.function dquat(qba::Quaternion, wba_b::AbstractVector)
Compute the time-derivative of the quaternion qba
that rotates a 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
.
Example
julia> q = Quaternion(1.0I);
julia> dquat(q,[1;0;0])
Quaternion{Float64}:
+ 0.0 + 0.5.i + 0.0.j + 0.0.k
ReferenceFrameRotations.inv_rotation
— Method.@inline function inv_rotation(R)
Compute the inverse rotation of R
, which can be:
- A direction cosina matrix (
DCM
); - An Euler angle and axis (
EulerAngleAxis
); - A set of Euler anlges (
EulerAngles
); or - A quaternion (
Quaternion
).
The output will have the same type as R
(DCM or quaternion).
Remarks
If R
is a DCM, than its transpose is computed instead of its inverse to reduce the computational burden. The both are equal if the DCM has unit norm. This must be verified by the user.
If R
is a quaternion, than its conjugate is computed instead of its inverse to reduce the computational burden. The both are equal if the quaternion has unit norm. This must be verified by the used.
Example
julia> D = angle_to_dcm(+pi/3,+pi/4,+pi/5,:ZYX);
julia> inv_rotation(D)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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.5236 rad ( 30.0000 deg)
Euler axis: [ -1.0000, -0.0000, -0.0000]
julia> Θ = EulerAngles(-pi/3, -pi/2, -pi, :YXZ);
julia> inv_rotation(Θ)
EulerAngles{Float64}:
R(Z): 3.1416 rad ( 180.0000 deg)
R(X): 1.5708 rad ( 90.0000 deg)
R(Y): 1.0472 rad ( 60.0000 deg)
julia> q = angle_to_quat(+pi/3,+pi/4,+pi/5,:ZYX);
julia> inv_rotation(q)
Quaternion{Float64}:
+ 0.8200711519756747 - 0.06526868310243991.i - 0.45794027732580056.j - 0.336918398289752.k
ReferenceFrameRotations.orthonormalize
— Method.function orthonormalize(dcm::DCM)
Perform the Gram-Schmidt orthonormalization process in the DCM 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 should have NaN
. Notice, however, that such input matrix is not a valid direction cosine matrix.
Example
julia> D = DCM(3I)
julia> orthonormalize(D)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
ReferenceFrameRotations.quat_to_angle
— Function.function quat_to_angle(q::Quaternion, rot_seq::Symbol = :ZYX)
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, then it defaults to :ZYX
.
Example
julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);
julia> quat_to_angle(q,:XYZ)
EulerAngles{Float64}(0.7853981633974484, 0.0, -0.0, :XYZ)
function quat_to_angleaxis(q::Quaternion{T}) where T
Convert the quaternion q
to a Euler angle and axis representation (see EulerAngleAxis
). By convention, the Euler angle will be kept between [0, π] rad.
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.
Example
julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);
julia> quat_to_angleaxis(q)
EulerAngleAxis{Float64}(0.7853981633974484, [1.0, 0.0, 0.0])
ReferenceFrameRotations.quat_to_dcm
— Method.function quat_to_dcm(q::Quaternion)
Convert the quaternion q
to a Direction Cosine Matrix (DCM).
Example
julia> q = Quaternion(cosd(45/2), sind(45/2), 0, 0);
julia> quat_to_dcm(q)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
1.0 0.0 0.0
0.0 0.707107 0.707107
0.0 -0.707107 0.707107
function smallangle_to_dcm(θx::Number, θy::Number, θz::Number; normalize = true)
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
, then the matrix will be normalized using the function orthonormalize
.
Example
julia> smallangle_to_dcm(+0.01, -0.01, +0.01)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
1.0 0.01 0.01
-0.01 1.0 0.01
-0.01 -0.01 1.0
function smallangle_to_quat(θx::Number, θy::Number, θz::Number)
Create a quaternion from three small rotations of angles θx
, θy
, and θz
[rad] about the axes X, Y, and Z, respectively.
Remarks
The quaternion is normalized.
Example
julia> smallangle_to_quat(+0.01, -0.01, +0.01)
Quaternion{Float64}:
+ 0.9999625021092433 + 0.004999812510546217.i - 0.004999812510546217.j + 0.004999812510546217.k
function smallangle_to_rot([T,] θx::Number, θy::Number, θz::Number[; normalize = true])
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, then if defaults to DCM
.
If T
is DCM
, then the resulting matrix will be orthonormalized using the orthonormalize
function if the keyword normalize
is true
.
Example
julia> dcm = smallangle_to_rot(+0.01, -0.01, +0.01)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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)
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
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.9999625021092433 + 0.004999812510546217.i - 0.004999812510546217.j + 0.004999812510546217.k
ReferenceFrameRotations.vect
— Method.@inline function vect(q::Quaternion)
Return the vectorial or imaginary part of the quaternion q
represented by a 3 × 1 vector of type SVector{3}
.
Base.:*
— Method.@inline function *(v::AbstractVector, q::Quaternion)
@inline function *(q::Quaternion, v::AbstractVector)
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).
Base.:*
— Method.function *(Θ₂::EulerAngles, Θ₁::EulerAngles)
Compute the composed rotation of Θ₁ -> Θ₂
. Notice that the rotation will be represented by Euler angles (see EulerAngles
) with the same rotation sequence as Θ₂
.
Base.:*
— Method.@inline function *(u::UniformScaling, q::Quaternion)
@inline function *(q::Quaternion, u::UniformScaling)
Compute qu*q
or q*qu
(Hamilton product), in which qu
is the scaled identity quaternion qu = u.λ * I
.
Base.:*
— Method.@inline function *(λ::Number, q::Quaternion)
@inline function *(q::Quaternion, λ::Number)
Compute λ*q
or q*λ
, in which λ
is a scalar.
Base.:*
— Method.@inline function *(q1::Quaternion, q2::Quaternion)
Compute the quaternion multiplication q1*q2
(Hamilton product).
Base.:*
— Method.function *(ea₂::EulerAngleAxis{T1}, ea₁::EulerAngleAxis{T2}) where {T1,T2}
Compute the composed rotation of ea₁ -> ea₂
. Notice that the rotation will be represented by a Euler angle and axis (see EulerAngleAxis
). By convention, the output angle will always be in the range [0, π] [rad].
Notice that the vector representing the axis in ea₁
and ea₂
must be unitary. This function neither verifies this nor normalizes the vector.
Base.:+
— Method.@inline function +(u::UniformScaling, q::Quaternion)
@inline function +(q::Quaternion, u::UniformScaling)
Compute qu + q
or q + qu
, in which qu
is the scaled identity quaternion qu = u.λ * I
.
Base.:+
— Method.@inline function +(qa::Quaternion, qb::Quaternion)
Compute qa + qb
.
Base.:-
— Method.@inline function -(u::UniformScaling, q::Quaternion)
@inline function -(q::Quaternion, u::UniformScaling)
Compute qu - q
or q - qu
, in which qu
is the scaled identity quaternion qu = u.λ * I
.
Base.:-
— Method.@inline function -(qa::Quaternion, qb::Quaternion)
Compute qa - qb
.
Base.:/
— Method.@inline function /(u::UniformScaling, q::Quaternion)
@inline function /(q::Quaternion, u::UniformScaling)
Compute qu/q
or q/qu
(Hamilton product), in which qu
is the scaled identity quaternion qu = u.λ * I
.
Base.:/
— Method.@inline function /(λ::Number, q::Quaternion)
@inline function /(q::Quaternion, λ::Number)
Compute the division λ/q
or q/λ
, in which λ
is a scalar.
Base.:/
— Method.@inline /(q1::Quaternion, q2::Quaternion) = q1*inv(q2)
Compute q1*inv(q2)
(Hamilton product).
Base.:\
— Method.@inline function \(u::UniformScaling, q::Quaternion)
@inline function \(q::Quaternion, u::UniformScaling)
Compute inv(qu)*q
or inv(q)*qu
(Hamilton product), in which qu
is the scaled identity quaternion qu = u.λ * I
.
Base.:\
— Method.@inline \(q::Quaternion, v::AbstractVector)
@inline \(v::AbstractVector, q::Quaternion)
Compute inv(q)*qv
or inv(qv)*q
in which qv
is a quaternion with real part 0
and vectorial/imaginary part v
(Hamilton product).
Base.:\
— Method.@inline \(q1::Quaternion, q2::Quaternion) = inv(q1)*q2
Compute inv(q1)*q2
.
Base.conj
— Method.@inline function conj(q::Quaternion)
Compute the complex conjugate of the quaternion q
:
q0 - q1.i - q2.j - q3.k
Base.copy
— Method.@inline function copy(q::Quaternion{T}) where T
Create a copy of the quaternion q
.
Base.getindex
— Method.@inline function getindex(q::Quaternion, ::Colon)
Transform the quaternion into a 4x1 vector of type T
.
Base.imag
— Method.@inline function imag(q::Quaternion)
Return the vectorial or imaginary part of the quaternion q
represented by a 3 × 1 vector of type SVector{3}
.
Base.real
— Method.@inline function real(q::Quaternion)
Return the real part of the quaternion q
: q0
.
Base.show
— Method.function display(ea::EulerAngleAxis{T}) where T
function show(io::IO, mime::MIME"text/plain", ea::EulerAngleAxis{T}) where T
Display in stdout
the Euler angle and axis ea
.
Base.show
— Method.function show(io::IO, Θ::EulerAngles{T}) where T
function show(io::IO, mime::MIME"text/plain", Θ::EulerAngles{T}) where T
Print the Euler angles Θ
to the IO io
.
Base.show
— Method.function show(io::IO, q::Quaternion{T}) where T
function show(io::IO, mime::MIME"text/plain", q::Quaternion{T}) where T
Print the quaternion q
to the stream io
.
Base.zeros
— Method.@inline function zeros(q::Quaternion{T}) where T
Create the null quaternion with the same type T
of another quaternion q
:
T(0) + T(0).i + T(0).j + T(0).k
Example
julia> q1 = Quaternion{Float32}(cosd(45/2),sind(45/2),0,0);
julia> zeros(q1)
Quaternion{Float32}:
+ 0.0 + 0.0.i + 0.0.j + 0.0.k
Base.zeros
— Method.@inline function zeros(::Type{Quaternion{T}}) where T
Create the null quaternion of type T
:
T(0) + T(0).i + T(0).j + T(0).k
If the type T
is omitted, then it defaults to Float64
.
Example
julia> zeros(Quaternion{Float32})
Quaternion{Float32}:
+ 0.0 + 0.0.i + 0.0.j + 0.0.k
julia> zeros(Quaternion)
Quaternion{Float64}:
+ 0.0 + 0.0.i + 0.0.j + 0.0.k