API

Quaternions.QuaternionType
Quaternion{T<:Real} <: Number

Quaternion number type with real and imaginary parts of type T.

QuaternionF16, QuaternionF32, and QuaternionF64 are aliases for Quaternion{Float16}, Quaternion{Float32}, and Quaternion{Float64}, respectively.

See also: quat, real, imag_part.

source
Quaternions.quatFunction
quat(w, [x, y, z])

Convert real numbers or arrays to quaternion. x, y, z defaults to zero.

Examples

julia> quat(7)
Quaternion{Int64}(7, 0, 0, 0)

julia> quat(1.0, 2, 3, 4)
QuaternionF64(1.0, 2.0, 3.0, 4.0)

julia> quat([1, 2, 3])
3-element Vector{Quaternion{Int64}}:
 Quaternion{Int64}(1, 0, 0, 0)
 Quaternion{Int64}(2, 0, 0, 0)
 Quaternion{Int64}(3, 0, 0, 0)
source
Base.realMethod
real(q::Quaternion)

Return the real part of the quaternion q.

See also: imag_part, quat

Examples

julia> real(quat(1,2,3,4))
1
source
Base.realMethod
real(A::AbstractArray{<:Quaternion})

Return an array containing the real part of each quaternion in A.

Examples

julia> real([quat(5,6,7,8), 9])
2-element Vector{Int64}:
 5
 9
source
Base.realMethod
real(T::Type{<:Quaternion})

Return the type that represents the real part of a value of type T. e.g: for T == Quaternion{R}, returns R. Equivalent to typeof(real(zero(T))).

Examples

julia> real(Quaternion{Int})
Int64
source
Quaternions.imag_partFunction
imag_part(q::Quaternion{T}) -> NTuple{3, T}

Return the imaginary part of the quaternion q.

Note that this function is different from Base.imag, which returns Real for complex numbers.

See also: real, conj.

Examples

julia> imag_part(Quaternion(1,2,3,4))
(2, 3, 4)
source
Base.roundMethod
round(q::Quaternion[, RoundingModeReal, [RoundingModeImaginary]]; kwargs...)
round(q::Quaternion, RoundingModeReal,
      RoundingModeImaginary1, RoundingModeImaginary2, RoundingModeImaginary3; kwargs...)

Return the nearest integral value of the same type as the quaternion-valued q to q, breaking ties using the specified RoundingModes.

The first RoundingMode is used for rounding the real part while the second is used for rounding the imaginary parts. Alternatively, a RoundingMode may be provided for each part.

The kwargs are the same as those for round(::Real[, RoundingMode]; kwargs...).

Example

julia> round(quat(3.14, 4.5, 8.3, -2.8))
QuaternionF64(3.0, 4.0, 8.0, -3.0)
source
Base.conjFunction
conj(q::Quaternion)

Compute the quaternion conjugate of a quaternion q.

Examples

julia> conj(Quaternion(1,2,3,4))
Quaternion{Int64}(1, -2, -3, -4)
source
Base.invFunction
inv(q::Quaternion)

Return the multiplicative inverse of q::Quaternion, such that q*inv(q) or inv(q)*q yields one(q) (the multiplicative identity) up to roundoff errors.

Examples

julia> inv(quat(1))
QuaternionF64(1.0, -0.0, -0.0, -0.0)

julia> inv(quat(1, 2, 0, 0))
QuaternionF64(0.2, -0.4, -0.0, -0.0)

julia> inv(quat(2//3))
Quaternion{Rational{Int64}}(3//2, 0//1, 0//1, 0//1)
source
Base.signFunction
sign(q::Quaternion) -> Quaternion

Return zero if q==0 and $q/|q|$ otherwise.

Examples

julia> sign(Quaternion(4, 0, 0, 0))
QuaternionF64(1.0, 0.0, 0.0, 0.0)

julia> sign(Quaternion(1, 0, 1, 0))
QuaternionF64(0.7071067811865475, 0.0, 0.7071067811865475, 0.0)
source
Quaternions.slerpFunction
slerp(qa::Quaternion, qb::Quaternion, t::Real)

Spherical linear interpolation (Slerp) between the inputs qa and qb. Since the input is normalized inside the function, the absolute value of the return value will be 1.

Examples

julia> using Quaternions

julia> qa = Quaternion(1,0,0,0)
Quaternion{Int64}(1, 0, 0, 0)

julia> qb = Quaternion(0,1,0,0)
Quaternion{Int64}(0, 1, 0, 0)

julia> slerp(qa, qb, 0.6)
QuaternionF64(0.5877852522924731, 0.8090169943749475, 0.0, 0.0)

julia> ans ≈ Quaternion(cospi(0.3), sinpi(0.3), 0, 0)
true
source
Quaternions.extend_analyticFunction
extend_analytic(f, q::Quaternion)

Evaluate the extension of the complex analytic function f to the quaternions at q.

Given $q = s + a u$, where $s$ is the real part, $u$ is a pure unit quaternion, and $a \ge 0$ is the magnitude of the imaginary part of $q$,

\[f(q) = \Re(f(z)) + \Im(f(z)) u,\]

is the extension of f to the quaternions, where $z = s + a i$ is a complex analog to $q$.

See Theorem 5 of [Sudbery1970] for details.

source