PrevUpHomeNext

utx::lerp


utx::lerp

utx::lerp is a function object of class utx::lerp_class used to calculate the linear interpolation of two values or points p1 and p2.

lerp(p1, p2, t) = p1 * (1-t) + p2 *t

p1, p2 can be not only floating point values, but also vector, array, or even matrix of floating point values.

It just requires that p1, p2, and t satisfy the following operators:

p1, p2 and t: operator*
p1 and p2: operator+, operator-

p1 and p2 must be the same type, t must be floating-type,

See the full requirements of below note.

Calling Sig

Default call, template argument type auto-deduction

constexpr auto l = utx::lerp(p1, p2, t);
constexpr auto l = utx::lerp.fn(p1, p2, t);

Explicit set p1, p2 type, auto-deduce t type

constexpr auto l = utx::lerp.fn<p_type>(p1, p2, t);

Explicit set p1, p2, t type

constexpr auto l = utx::lerp.fn<p_type, t_type>(p1, p2, t);

Note

[Note] Note

utx::lerp(p1, p2, t) requires the following condition:

  • t is floating type;
  • p1 + p2 is valid, and its type is the same type of p1, p2;
  • p1 - p2 is valid, and its type is the same type of p1, p2;
  • Suppose t1 is float, p1 * t1 is valid, and its type is the same type of p1, p2; (t1 is float)
  • p1 * t is valid, and its type is convertible to type of p1, p2; (t is floating)
  • p1 * t + p2 is valid, and its convertible to type of p1, p2;

c++ example

#include <utxcpp/core.hpp>
#include <utxcpp/numeric.hpp>

int main()
{
	constexpr utx::fx32 a = 1.3f;
	constexpr utx::fx32 b = 6.3f;
	constexpr auto c = utx::lerp(a, b, 0.43);
	utx::print(c);
}

See Also

utx::cos

utx::print


PrevUpHomeNext