kyosu v0.1.0
Complex Without Complexes
 
Loading...
Searching...
No Matches

◆ slerp

kyosu::slerp = eve::functor<slerp_t>
inlineconstexpr

Computes the spherical interpolation between unitary quaternions.

Header file

#include <kyosu/functions.hpp>

Callable Signatures

namespace kyosu
{
constexpr auto slerp(auto z0, auto z1, floating_ordered_value t) noexcept;
}
constexpr auto slerp
Computes the spherical interpolation between unitary quaternions.
Definition: slerp.hpp:81
Main KYOSU namespace.
Definition: cinf.hpp:13

Parameters

  • z0, z1: unitary quaternions to process.
  • t: floating value interpolation coefficient.

Return value

The value of the spherical interpolation (or extrapolation) between z0 and z1 is returned.

Note
The function does not assume that z0 and z1 are unitary. The option assume_unitary allows to avoid unecessary normalizations if z0 and are already normalized.

Example

#include <kyosu/kyosu.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
using kyosu::slerp;
using e_t = float;
using we_t = eve::wide<float, eve::fixed<2>>;
using wc_t = eve::wide<kyosu::complex_t<float>, eve::fixed<2>>;
using wq_t = eve::wide<kyosu::quaternion_t<float>, eve::fixed<2>>;
using kyosu::sign;
std::cout << "Real: "<< "\n";
e_t e0(1);
e_t e1(-1);
e_t t(0.3);
std::cout << e0 << ", " << e1 << ", " << t << " -> " << slerp(e0, e1, t) << "\n";
std::cout << e0 << ", " << e0 << ", " << t << " -> " << slerp(e0, e0, t) << "\n";
we_t we0(e0);
we_t we1(e1);
std::cout << we0 << ", " << we1 << ", " << t<< " -> " << slerp(we0, we1, t) << "\n";
std::cout << "Complex: "<< "\n";
c_t c0(1, 5);
c_t c1(5, 9);
c0 = sign(c0);
c1 = sign(c1);
std::cout << c0 << ", " << c1 << ", " << t << " -> " << slerp(c0, c1, t) << "\n";
std::cout << c0 << ", " << c0 << ", " << t << " -> " << slerp(c0, c0, t) << "\n";
wc_t wc0(c0, c1);
wc_t wc1(c1, c1);
std::cout << wc0 << ", " << wc1 << ", " << t << " -> " << slerp(wc0, wc1, t) << "\n";
std::cout << "Quaternion: "<< "\n";
q_t q0(1, 5, 2, 3);
q_t q1(5, 9, 6, 7);
q0 = sign(q0);
q1 = sign(q1);
std::cout << q0 << ", " << q1 << ", " << t << " -> " << slerp(q0, q1, t) << "\n";
std::cout << q0 << ", " << q0 << ", " << t << " -> " << slerp(q0, q0, t) << "\n";
wq_t wq0(q0, q1);
wq_t wq1(q1, q1);
std::cout << wq0 << ", " << wq1 << ", " << t << " -> " << slerp(wq0, wq1, t) << "\n";
std::cout << "Mixed: "<< "\n";
std::cout << c0 << ", " << q1 << ", " << t << " -> " << kyosu::slerp(c0, q1, t) << std::endl;
std::cout << e0 << ", " << q1 << ", " << t << " -> " << kyosu::slerp(e0, q1, t) << std::endl;
std::cout << c0 << ", " << wq1<< ", " << t << " -> " << kyosu::slerp(c0, wq1, t) << std::endl;
std::cout << we0<< ", " << wq1 << ", " << t << " -> " << kyosu::slerp(we0, wq1, t) << std::endl;
std::cout << we0<< ", " << q1 << ", " << t << " -> " << kyosu::slerp(we0, q1, t) << std::endl;
return 0;
}
constexpr auto sign
Computes tne normalized value z/abs(z) if z is not zero else 0.
Definition: sign.hpp:63
as_cayley_dickson_n_t< 4, T > quaternion_t
Type alias for quaternion numbers.
Definition: quaternion.hpp:24
as_cayley_dickson_n_t< 2, T > complex_t
Type alias for complex numbers.
Definition: complex.hpp:27