quaternion.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 INRIA CNRS
3 //
4 
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 
25  quaternion::assignQuaternion(quat, M.rotation());
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)
39  {
41  BOOST_CHECK_MESSAGE(
42  (q.coeffs().array().abs() <= 1).all(),
43  "Quaternion coeffs out of bounds: " << i << ' ' << q.coeffs().transpose());
44  }
45 }
46 
47 BOOST_AUTO_TEST_CASE(test_isNormalized)
48 {
49  srand(0);
50 
51  using namespace pinocchio;
52  typedef Eigen::Quaternion<double> Quaternion;
53  typedef Quaternion::Coefficients Vector4;
54 
55 #ifdef NDEBUG
56  const int max_test = 1e6;
57 #else
58  const int max_test = 1e2;
59 #endif
60  for (int i = 0; i < max_test; ++i)
61  {
62  Quaternion q;
63  q.coeffs() = Vector4::Random() + Vector4::Constant(2);
64  BOOST_CHECK(!quaternion::isNormalized(q));
65 
66  q.normalize();
67  BOOST_CHECK(quaternion::isNormalized(q));
68  }
69 
70  // Specific check for the Zero vector
71  BOOST_CHECK(!quaternion::isNormalized(Quaternion(Vector4::Zero())));
72 }
73 
74 BOOST_AUTO_TEST_SUITE_END()
quaternion.hpp
pinocchio::quaternion::uniformRandom
void uniformRandom(Eigen::QuaternionBase< Derived > &q)
Uniformly random quaternion sphere.
Definition: math/quaternion.hpp:114
quat
quat
pinocchio::SE3Tpl< context::Scalar, context::Options >
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
pinocchio::quaternion::isNormalized
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.
Definition: math/quaternion.hpp:229
pinocchio::quaternion::assignQuaternion
void assignQuaternion(Eigen::QuaternionBase< D > &quat, const Eigen::MatrixBase< Matrix3 > &R)
Definition: math/quaternion.hpp:214
pinocchio::python::context::Quaternion
Eigen::Quaternion< Scalar, Options > Quaternion
Definition: bindings/python/context/generic.hpp:49
se3.hpp
M
M
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_assignQuaternion)
Definition: quaternion.cpp:15
pinocchio::q
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
Definition: joint-configuration.hpp:1083
pinocchio::SE3Tpl< context::Scalar, context::Options >::Quaternion
Eigen::Quaternion< Scalar, Options > Quaternion
Definition: spatial/se3-tpl.hpp:54
pinocchio::SE3Tpl::Random
static SE3Tpl Random()
Definition: spatial/se3-tpl.hpp:154
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


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