rbdlsim/3rdparty/rbdl/tests/MathTests.cc

80 lines
1.7 KiB
C++
Raw Permalink Normal View History

#include "rbdl_tests.h"
2020-10-03 22:55:14 +02:00
#include "rbdl/Logging.h"
#include "rbdl/rbdl_math.h"
#include "rbdl/rbdl_mathutils.h"
#include <iostream>
const double TEST_PREC = 1.0e-14;
using namespace std;
using namespace RigidBodyDynamics::Math;
using namespace Catch::Matchers::Floating;
2020-10-03 22:55:14 +02:00
struct MathFixture {
};
TEST_CASE(__FILE__"_GaussElimPivot", "") {
2020-10-03 22:55:14 +02:00
ClearLogOutput();
MatrixNd A;
A.resize(3,3);
VectorNd b(3);
VectorNd x(3);
A(0,0) = 0; A(0,1) = 2; A(0,2) = 1;
A(1,0) = 1; A(1,1) = 1; A(1,2) = 5;
A(2,0) = 0; A(2,1) = 0; A(2,2) = 1;
b[0] = 1;
b[1] = 2;
b[2] = 3;
VectorNd test_result (3);
test_result[0] = -12;
test_result[1] = -1;
test_result[2] = 3;
LinSolveGaussElimPivot (A, b, x);
REQUIRE_THAT (test_result, AllCloseVector(x));
2020-10-03 22:55:14 +02:00
A(0,0) = 0; A(0,1) = -2; A(0,2) = 1;
A(1,0) = 1; A(1,1) = 1; A(1,2) = 5;
A(2,0) = 0; A(2,1) = 0; A(2,2) = 1;
LinSolveGaussElimPivot (A, b, x);
test_result[0] = -14;
test_result[1] = 1;
test_result[2] = 3;
x[0] += 1.0e-13;
2020-10-03 22:55:14 +02:00
REQUIRE_THAT (test_result, AllCloseVector(x));
2020-10-03 22:55:14 +02:00
}
TEST_CASE(__FILE__"_QuaternionSlerpNegativeCosHalfTheta", "") {
ClearLogOutput();
2020-10-03 22:55:14 +02:00
Quaternion q1 (-0.518934,0.561432,-0.074923,0.640225);
Quaternion q2 (0.54702,-0.564195,0.078871,-0.613379);
2020-10-03 22:55:14 +02:00
Quaternion s = q1.slerp (0.2021, q2);
Quaternion q_ref (0.0068865, 0.406762, -0.000610507, 0.913655);
2020-10-03 22:55:14 +02:00
REQUIRE_THAT (s, AllCloseVector(q_ref));
}
2020-10-03 22:55:14 +02:00
TEST_CASE(__FILE__"_QuaternionFromMatrixSingularity", "") {
ClearLogOutput();
Matrix3d m;
m << -1., 0, 0, 0, 1, 0, 0, 0, -1;
2020-10-03 22:55:14 +02:00
Quaternion q = Quaternion::fromMatrix(m);
Quaternion q_ref (0., 1., 0., 0.);
2020-10-03 22:55:14 +02:00
REQUIRE_THAT (q, AllCloseVector(q_ref));
2020-10-03 22:55:14 +02:00
}