rotation.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA
3 //
4 
5 #include <iostream>
6 
7 #include <pinocchio/math/rotation.hpp>
8 #include <pinocchio/math/sincos.hpp>
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  const int max_tests = 1e5;
22  for(int k = 0; k < max_tests; ++k)
23  {
24  const double theta = std::rand();
25  double cos_value, sin_value;
26 
27  pinocchio::SINCOS(theta,&sin_value,&cos_value);
28  Eigen::Vector3d axis(Eigen::Vector3d::Random().normalized());
29 
30  Eigen::Matrix3d rot; toRotationMatrix(axis,cos_value,sin_value,rot);
31  Eigen::Matrix3d rot_ref = Eigen::AngleAxisd(theta,axis).toRotationMatrix();
32 
33  BOOST_CHECK(rot.isApprox(rot_ref));
34  }
35 }
36 
37 BOOST_AUTO_TEST_CASE(test_orthogonal_projection)
38 {
39  using namespace pinocchio;
40  const int max_tests = 1e5;
41 
42  typedef Eigen::Vector4d Vector4;
43  typedef Eigen::Quaterniond Quaternion;
44  typedef Eigen::Matrix3d Matrix3;
45 
46  for(int k = 0; k < max_tests; ++k)
47  {
48  const Vector4 vec4 = Vector4::Random();
49  const Quaternion quat(vec4.normalized());
50 
51  const Matrix3 rot = quat.toRotationMatrix();
52 
53  Matrix3 rot_proj = orthogonalProjection(rot);
54  BOOST_CHECK(rot.isApprox(rot_proj));
55  }
56 
57  for(int k = 0; k < max_tests; ++k)
58  {
59  const Matrix3 mat = Matrix3::Random();
60 
61  Matrix3 rot_proj = orthogonalProjection(mat);
62  BOOST_CHECK((rot_proj.transpose()*rot_proj).isIdentity());
63  BOOST_CHECK(fabs(rot_proj.determinant() - 1.) <= Eigen::NumTraits<double>::dummy_precision());
64  }
65 }
66 
67 BOOST_AUTO_TEST_SUITE_END()
68 
69 
BOOST_AUTO_TEST_CASE(test_toRotationMatrix)
Definition: rotation.cpp:18
axis
mat
quat
void SINCOS(const S1 &a, S2 *sa, S3 *ca)
Computes sin/cos values of a given input scalar.
Definition: sincos.hpp:26
Main pinocchio namespace.
Definition: timings.cpp:30
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:24


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04