API
Quaternions.Quaternion — TypeQuaternion{T<:Real} <: NumberQuaternion 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.
Quaternions.quat — Functionquat(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)Base.real — Methodreal(q::Quaternion)Return the real part of the quaternion q.
Examples
julia> real(quat(1,2,3,4))
1Base.real — Methodreal(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
9Base.real — Methodreal(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})
Int64Quaternions.imag_part — Functionimag_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.
Examples
julia> imag_part(Quaternion(1,2,3,4))
(2, 3, 4)Base.round — Methodround(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)Base.conj — Functionconj(q::Quaternion)Compute the quaternion conjugate of a quaternion q.
Examples
julia> conj(Quaternion(1,2,3,4))
Quaternion{Int64}(1, -2, -3, -4)Base.inv — Functioninv(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)Base.sign — Functionsign(q::Quaternion) -> QuaternionReturn 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)Quaternions.slerp — Functionslerp(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)
trueQuaternions.extend_analytic — Functionextend_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.
- Sudbery1970Sudbery (1979). Quaternionic analysis. Mathematical Proceedings of the Cambridge Philosophical Society,85, pp 199225 doi:10.1017/S030500410005563