quaternion.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA CNRS
3 //
4 
5 #include <pinocchio/math/quaternion.hpp>
6 #include <pinocchio/spatial/se3.hpp>
7 
8 #include <boost/variant.hpp> // to avoid C99 warnings
9 
10 #include <boost/test/unit_test.hpp>
11 #include <boost/utility/binary.hpp>
12 
13 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
14 
15 BOOST_AUTO_TEST_CASE(test_assignQuaternion)
16 {
17  using namespace pinocchio;
18  const int max_tests = 1e5;
19  for(int k = 0; k < max_tests; ++k)
20  {
21  const SE3 M(SE3::Random());
22  SE3::Quaternion quat_ref(M.rotation());
23 
26 
27  BOOST_CHECK(quat.coeffs().isApprox(quat_ref.coeffs()));
28  }
29 }
30 
31 BOOST_AUTO_TEST_CASE(test_uniformRandom)
32 {
33  srand(0);
34 
35  using namespace pinocchio;
36  Eigen::Quaternion<double> q;
37 
38  for (int i = 0; i < (1 << 10); ++i) {
40  BOOST_CHECK_MESSAGE((q.coeffs().array().abs() <= 1).all(),
41  "Quaternion coeffs out of bounds: " << i << ' ' << q.coeffs().transpose());
42  }
43 }
44 
45 BOOST_AUTO_TEST_CASE(test_isNormalized)
46 {
47  srand(0);
48 
49  using namespace pinocchio;
50  typedef Eigen::Quaternion<double> Quaternion;
51  typedef Quaternion::Coefficients Vector4;
52 
53 #ifdef NDEBUG
54  const int max_test = 1e6;
55 #else
56  const int max_test = 1e2;
57 #endif
58  for(int i = 0; i < max_test; ++i)
59  {
60  Quaternion q;
61  q.coeffs() = Vector4::Random() + Vector4::Constant(2);
62  BOOST_CHECK(!quaternion::isNormalized(q));
63 
64  q.normalize();
65  BOOST_CHECK(quaternion::isNormalized(q));
66  }
67 
68  // Specific check for the Zero vector
69  BOOST_CHECK(!quaternion::isNormalized(Quaternion(Vector4::Zero())));
70 }
71 
72 BOOST_AUTO_TEST_SUITE_END()
73 
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Eigen::Quaternion< Scalar, Options > Quaternion
quat
void uniformRandom(const Eigen::QuaternionBase< Derived > &q)
Uniformly random quaternion sphere.
ConstAngularRef rotation() const
Definition: se3-base.hpp:37
Main pinocchio namespace.
Definition: timings.cpp:28
void assignQuaternion(Eigen::QuaternionBase< D > &quat, const Eigen::MatrixBase< Matrix3 > &R)
bool isNormalized(const Eigen::QuaternionBase< Quaternion > &quat, const typename Quaternion::Coefficients::RealScalar &prec=Eigen::NumTraits< typename Quaternion::Coefficients::RealScalar >::dummy_precision())
Check whether the input quaternion is Normalized within the given precision.
M
BOOST_AUTO_TEST_CASE(test_assignQuaternion)
Definition: quaternion.cpp:15


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:32