22#include <Eigen/Geometry>
57template <
typename Scalar>
72 Scalar theta = sqrt(theta_sq);
81 ret = sin(theta) / theta;
96template <
typename Scalar>
108 return cos(sqrt(theta_sq));
120template <
typename Derived>
121inline Eigen::Quaternion<typename Derived::Scalar>
124 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
125 using Scalar =
typename Derived::Scalar;
126 Scalar theta_sq = vec.squaredNorm();
128 Eigen::Quaternion<Scalar> ret;
129 ret.vec() = vecscale * vec;
130 ret.w() =
cos_sq(theta_sq);
141template <
typename Derived>
142inline Eigen::Quaternion<typename Derived::Scalar>
145 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Derived, 3);
146 using Scalar =
typename Derived::Scalar;
147 const Scalar theta_sq = vec.squaredNorm();
153 Eigen::Quaternion<Scalar> ret;
154 ret.vec() = vecscale * vec;
155 ret.w() =
cos_sq(sq_half_theta);
164template <
typename Scalar>
170 (theta * theta) /
Scalar(6) +
172 (
Scalar(7) * theta * theta * theta * theta) /
Scalar(360) +
174 (
Scalar(31) * theta * theta * theta * theta * theta * theta) /
Scalar(15120);
186template <
typename Scalar>
187inline Eigen::Matrix<Scalar, 3, 1>
196 const Scalar sqr_vecnorm = quat.vec().squaredNorm();
209 const Scalar x2 = sqr_vecnorm / (quat.w() * quat.w());
211 return quat.vec() * phiOverSin;
219 if (sqr_vecnorm ==
Scalar(0)) {
220 return Eigen::Matrix<Scalar, 3, 1>::Zero();
223 const Scalar vecnorm = sqrt(sqr_vecnorm);
226 const Scalar phi = atan2(vecnorm, quat.w());
233 return quat.vec() * (phi / vecnorm);
243template <
typename Scalar>
244Eigen::Matrix<Scalar, 3, 1>
C interface to math library.
Interoperability helpers connecting internal math types and Eigen.
C++-only functionality in the Math helper library.
Definition m_documentation.hpp:15
Scalar cos_sq(Scalar theta_sq)
Computes cos(theta) given theta^2, staying differentiable at theta = 0.
Definition m_quatexpmap.hpp:98
Scalar sinc_sq(Scalar theta_sq)
Computes the "historical" (un-normalized) sinc(Theta), using theta^2 to allow us to handle sqrt(0) be...
Definition m_quatexpmap.hpp:59
Eigen::Quaternion< typename Derived::Scalar > quat_exp_so3(Eigen::MatrixBase< Derived > const &vec)
Fully-templated free function for quaternion exponentiation, SO(3) version as described by Grassia.
Definition m_quatexpmap.hpp:143
Scalar cscTaylorExpansion(Scalar theta)
Taylor series expansion of theta over sin(theta), also known as cosecant, for use near 0 when you wan...
Definition m_quatexpmap.hpp:166
Eigen::Matrix< Scalar, 3, 1 > quat_ln_so3(const Eigen::Quaternion< Scalar > &quat)
Fully-templated free function for the quaternion log map, SO(3) version as described by Grassia.
Definition m_quatexpmap.hpp:245
Eigen::Quaternion< typename Derived::Scalar > quat_exp(Eigen::MatrixBase< Derived > const &vec)
Fully-templated free function for quaternion exponentiation.
Definition m_quatexpmap.hpp:122
Eigen::Matrix< Scalar, 3, 1 > quat_ln(Eigen::Quaternion< Scalar > const &quat)
Fully-templated free function for quaternion log map.
Definition m_quatexpmap.hpp:188
constexpr double quat_small_sqr_vecnorm
Squared vector norm below which the quat maps switch to a series expansion, i.e.
Definition m_quatexpmap.hpp:91
static double get()
Machine epsilon is 1e-53, so double-precision fourth root is roughly 1e-13.
Definition m_quatexpmap.hpp:36
static float get()
Machine epsilon is 1e-24, so double-precision fourth root is roughly 1e-6.
Definition m_quatexpmap.hpp:45
Definition m_quatexpmap.hpp:30