21 #ifndef EIGEN_UTILS_H_
22 #define EIGEN_UTILS_H_
24 #include <Eigen/Dense>
25 #include <Eigen/Geometry>
29 template<
class Derived>
30 inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
skew(
31 const Eigen::MatrixBase<Derived> & vec) {
32 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
33 return (Eigen::Matrix<typename Derived::Scalar, 3, 3>() << 0.0, -vec[2], vec[1],
34 vec[2], 0.0, -vec[0], -vec[1], vec[0], 0.0).finished();
44 template<
class Derived>
45 inline Eigen::Matrix<typename Derived::Scalar, 4, 4>
omegaMatJPL(
46 const Eigen::MatrixBase<Derived> & vec) {
47 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
48 return (Eigen::Matrix<typename Derived::Scalar, 4, 4>() << 0, vec[2], -vec[1],
49 vec[0], -vec[2], 0, vec[0], vec[1], vec[1], -vec[0], 0, vec[2], -vec[0],
61 template<
class Derived>
63 const Eigen::MatrixBase<Derived> & vec) {
64 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
65 return (Eigen::Matrix<typename Derived::Scalar, 4, 4>() << 0, -vec[2], vec[1],
66 vec[0], vec[2], 0, -vec[0], vec[1], -vec[1], vec[0], 0, vec[2], -vec[0],
67 -vec[1], -vec[2], 0).finished();
79 template<
class Derived>
80 inline Eigen::Matrix<typename Derived::Scalar, 4, 3>
xiMat(
81 const Eigen::MatrixBase<Derived> & q_vec) {
82 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived, 4, 1);
84 return (Eigen::Matrix<typename Derived::Scalar, 4, 3>() <<
86 q_vec[3] * Eigen::Matrix<typename Derived::Scalar, 3, 3>::Identity()
87 +
skew(q_vec.template head<3>()), -q_vec.template head<3>().transpose()
93 template<
class Derived>
95 const Eigen::MatrixBase<Derived> & theta) {
96 typedef typename Derived::Scalar Scalar;
97 EIGEN_STATIC_ASSERT_FIXED_SIZE (Derived);
98 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
99 const Scalar q_squared = theta.squaredNorm() / 4.0;
103 > (sqrt(1 - q_squared), theta[0] * 0.5, theta[1] * 0.5, theta[2] * 0.5);
105 const Scalar w = 1.0 / sqrt(1 + q_squared);
106 const Scalar f = w * 0.5;
108 > (w, theta[0] * f, theta[1] * f, theta[2] * f);
115 const std::string & info) {
117 rows = Eigen::MatrixBase < D > ::RowsAtCompileTime,
118 cols = Eigen::MatrixBase < D > ::ColsAtCompileTime
121 for (
int i = 0; i < rows; ++i) {
122 for (
int j = 0; j < cols; ++j) {
123 if (std::isnan(mat(i, j))) {
124 std::cerr <<
"=== ERROR === " << info <<
": NAN at index [" << i <<
","
125 << j <<
"]" << std::endl;
128 if (std::isinf(mat(i, j))) {
129 std::cerr <<
"=== ERROR === " << info <<
": INF at index [" << i <<
","
130 << j <<
"]" << std::endl;
138 #endif // EIGEN_UTILS_H_