From 56224b4c45c9d1bd88fa05c7be05aa90cfb915c5 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Mon, 17 Oct 2022 21:13:48 +0900 Subject: [PATCH] add docstring of `slerp` --- src/Quaternion.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Quaternion.jl b/src/Quaternion.jl index 7b509510..81393e59 100644 --- a/src/Quaternion.jl +++ b/src/Quaternion.jl @@ -385,6 +385,29 @@ function rotationmatrix_normalized(q::Quaternion) xz - sy yz + sx 1 - (xx + yy)] end +""" + 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 +```jldoctest +julia> using Quaternions + +julia> qa = Quaternion(1,0,0,0) +Quaternion{Int64}(1, 0, 0, 0, false) + +julia> qb = Quaternion(0,1,0,0) +Quaternion{Int64}(0, 1, 0, 0, false) + +julia> slerp(qa, qb, 0.6) +QuaternionF64(0.5877852522924731, 0.8090169943749475, 0.0, 0.0, true) + +julia> ans ≈ Quaternion(cospi(0.3), sinpi(0.3), 0, 0) +true +``` +""" @inline function slerp(qa0::Quaternion{T}, qb0::Quaternion{T}, t::T) where T<:Real # http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ iszero(qa0) && throw(DomainError(qa0, "The input quaternion must be non-zero."))