Cheetah Software  1.0
Interpolation.h
Go to the documentation of this file.
1 
6 #ifndef PROJECT_INTERPOLATION_H
7 #define PROJECT_INTERPOLATION_H
8 
9 #include <assert.h>
10 #include <type_traits>
11 
12 namespace Interpolate {
13 
17 template <typename y_t, typename x_t>
18 y_t lerp(y_t y0, y_t yf, x_t x) {
19  static_assert(std::is_floating_point<x_t>::value,
20  "must use floating point value");
21  assert(x >= 0 && x <= 1);
22  return y0 + (yf - y0) * x;
23 }
24 
28 template <typename y_t, typename x_t>
29 y_t cubicBezier(y_t y0, y_t yf, x_t x) {
30  static_assert(std::is_floating_point<x_t>::value,
31  "must use floating point value");
32  assert(x >= 0 && x <= 1);
33  y_t yDiff = yf - y0;
34  x_t bezier = x * x * x + x_t(3) * (x * x * (x_t(1) - x));
35  return y0 + bezier * yDiff;
36 }
37 
42 template <typename y_t, typename x_t>
43 y_t cubicBezierFirstDerivative(y_t y0, y_t yf, x_t x) {
44  static_assert(std::is_floating_point<x_t>::value,
45  "must use floating point value");
46  assert(x >= 0 && x <= 1);
47  y_t yDiff = yf - y0;
48  x_t bezier = x_t(6) * x * (x_t(1) - x);
49  return bezier * yDiff;
50 }
51 
56 template <typename y_t, typename x_t>
57 y_t cubicBezierSecondDerivative(y_t y0, y_t yf, x_t x) {
58  static_assert(std::is_floating_point<x_t>::value,
59  "must use floating point value");
60  assert(x >= 0 && x <= 1);
61  y_t yDiff = yf - y0;
62  x_t bezier = x_t(6) - x_t(12) * x;
63  return bezier * yDiff;
64 }
65 
66 } // namespace Interpolate
67 
68 #endif // PROJECT_INTERPOLATION_H
y_t lerp(y_t y0, y_t yf, x_t x)
Definition: Interpolation.h:18
y_t cubicBezierFirstDerivative(y_t y0, y_t yf, x_t x)
Definition: Interpolation.h:43
y_t cubicBezier(y_t y0, y_t yf, x_t x)
Definition: Interpolation.h:29
y_t cubicBezierSecondDerivative(y_t y0, y_t yf, x_t x)
Definition: Interpolation.h:57