rotation.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA
3 //
4 
5 #include <iostream>
6 
9 #include <Eigen/Geometry>
10 
11 #include <boost/variant.hpp> // to avoid C99 warnings
12 
13 #include <boost/test/unit_test.hpp>
14 #include <boost/utility/binary.hpp>
15 
16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
17 
18 BOOST_AUTO_TEST_CASE(test_toRotationMatrix)
19 {
20  using namespace pinocchio;
21 #ifndef NDEBUG
22  const int max_tests = 1e5;
23 #else
24  const int max_tests = 1e2;
25 #endif
26  for (int k = 0; k < max_tests; ++k)
27  {
28  const double theta = std::rand();
29  double cos_value, sin_value;
30 
31  pinocchio::SINCOS(theta, &sin_value, &cos_value);
32  const Eigen::Vector3d axis(Eigen::Vector3d::Random().normalized());
33 
34  Eigen::Matrix3d rot;
35  toRotationMatrix(axis, cos_value, sin_value, rot);
36  Eigen::Matrix3d rot2;
37  toRotationMatrix(axis, theta, rot2);
38 
39  const Eigen::Matrix3d rot_ref = Eigen::AngleAxisd(theta, axis).toRotationMatrix();
40 
41  BOOST_CHECK(rot.isApprox(rot_ref));
42  BOOST_CHECK(rot2.isApprox(rot_ref));
43  }
44 }
45 
46 BOOST_AUTO_TEST_CASE(test_orthogonal_projection)
47 {
48  using namespace pinocchio;
49 #ifndef NDEBUG
50  const int max_tests = 1e5;
51 #else
52  const int max_tests = 1e2;
53 #endif
54 
55  typedef Eigen::Vector4d Vector4;
56  typedef Eigen::Quaterniond Quaternion;
57  typedef Eigen::Matrix3d Matrix3;
58 
59  for (int k = 0; k < max_tests; ++k)
60  {
61  const Vector4 vec4 = Vector4::Random();
62  const Quaternion quat(vec4.normalized());
63 
64  const Matrix3 rot = quat.toRotationMatrix();
65 
66  Matrix3 rot_proj = orthogonalProjection(rot);
67  BOOST_CHECK(rot.isApprox(rot_proj));
68  }
69 
70  for (int k = 0; k < max_tests; ++k)
71  {
72  const Matrix3 mat = Matrix3::Random();
73 
74  Matrix3 rot_proj = orthogonalProjection(mat);
75  BOOST_CHECK((rot_proj.transpose() * rot_proj).isIdentity());
76  BOOST_CHECK(fabs(rot_proj.determinant() - 1.) <= Eigen::NumTraits<double>::dummy_precision());
77  }
78 }
79 
80 BOOST_AUTO_TEST_SUITE_END()
sincos.hpp
rotation.hpp
quat
quat
pinocchio::SINCOS
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:27
pinocchio::python::context::Quaternion
Eigen::Quaternion< Scalar, Options > Quaternion
Definition: bindings/python/context/generic.hpp:49
mat
mat
axis
axis
pinocchio::toRotationMatrix
void toRotationMatrix(const Eigen::MatrixBase< Vector3 > &axis, const Scalar &cos_value, const Scalar &sin_value, const Eigen::MatrixBase< Matrix3 > &res)
Computes a rotation matrix from a vector and values of sin and cos orientations values.
Definition: rotation.hpp:26
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_toRotationMatrix)
Definition: rotation.cpp:18
pinocchio.utils.rand
def rand(n)
Definition: bindings/python/pinocchio/utils.py:41
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:48