Cheetah Software  1.0
test_math.cpp
Go to the documentation of this file.
1 
6 #include "Math/Interpolation.h"
7 #include "Math/MathUtilities.h"
8 #include "cppTypes.h"
9 #include "gmock/gmock.h"
10 #include "gtest/gtest.h"
11 
12 // test linear interpolation
13 TEST(Math, InterpolateLinear) {
14  Vec3<double> y0(1, 2, 3);
15  Vec3<double> y1(6, 5, 4);
16 
17  Vec3<double> yInterpRef = y0 + 0.75 * (y1 - y0);
18 
19  Vec3<double> yInterp = Interpolate::lerp(y0, y1, 0.75);
20 
21  EXPECT_TRUE(almostEqual(yInterp, yInterpRef, .001));
22 }
23 
24 // test bezier interpolation derivatives
25 TEST(Math, BezierInterpolationFirstDerivative) {
26  Vec3<double> y0(1, 2, 3);
27  Vec3<double> y1(6, 5, 4);
28 
29  double dx = .00001;
30  double x = 0.23;
31  Vec3<double> yInterpX = Interpolate::cubicBezier(y0, y1, x);
32  Vec3<double> yInterpXdx = Interpolate::cubicBezier(y0, y1, x + dx);
33 
34  Vec3<double> dyInterpDxRef = (yInterpXdx - yInterpX) / dx;
35 
37 
38  EXPECT_TRUE(almostEqual(dyInterpDx, dyInterpDxRef, .001));
39 
40  for (int i = 0; i < 3; i++) {
41  EXPECT_TRUE(yInterpX(i) > y0(i) && yInterpX(i) < y1(i));
42  }
43 }
44 
45 // test bezier interpolation derivatives
46 TEST(Math, BezierInterpolationSecondDerivative) {
47  Vec3<double> y0(1, 2, 3);
48  Vec3<double> y1(6, 5, 4);
49 
50  double dx = .00001;
51  double x = 0.23;
53  Vec3<double> yInterpXdx =
55 
56  Vec3<double> dyInterpDxRef = (yInterpXdx - yInterpX) / dx;
57 
59 
60  EXPECT_TRUE(almostEqual(dyInterpDx, dyInterpDxRef, .001));
61 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
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
TEST(Math, InterpolateLinear)
Definition: test_math.cpp:13
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23
Utility functions to interpolate between two values.
Utility functions for math.
y_t cubicBezierSecondDerivative(y_t y0, y_t yf, x_t x)
Definition: Interpolation.h:57