37template <
typename Type>
40 return rad *
static_cast<Type
>(180.0 / M_PI);
46template <
typename Type>
49 return deg *
static_cast<Type
>(M_PI / 180.0);
53static inline constexpr float operator"" _deg(
long double degrees)
55 return static_cast<float>(degrees * M_PI / 180.0);
57static inline constexpr float operator"" _rad(
long double radians)
59 return static_cast<float>(radians);
69template <
typename Type>
72 while (angle >= M_PI) {
75 while (angle < -M_PI) {
89template <
typename Type>
92 Eigen::Matrix<Type, 3, 1> angles;
93 const Eigen::Matrix<Type, 3, 3> dcm = q.toRotationMatrix();
95 angles.y() = asin(-dcm.coeff(2, 0));
97 if ((std::fabs(angles.y() -
static_cast<Type
>(M_PI / 2))) <
static_cast<Type
>(1.0e-3)) {
99 angles.z() = atan2(dcm.coeff(1, 2), dcm.coeff(0, 2));
100 }
else if ((std::fabs(angles.y() +
static_cast<Type
>(M_PI / 2))) <
static_cast<Type
>(1.0e-3)) {
102 angles.z() = atan2(-dcm.coeff(1, 2), -dcm.coeff(0, 2));
104 angles.x() = atan2(dcm.coeff(2, 1), dcm.coeff(2, 2));
105 angles.z() = atan2(dcm.coeff(1, 0), dcm.coeff(0, 0));
117template <
typename Type>
120 return Eigen::Quaternion<Type>(
121 Eigen::AngleAxis<Type>(euler[2], Eigen::Matrix<Type, 3, 1>::UnitZ()) *
122 Eigen::AngleAxis<Type>(euler[1], Eigen::Matrix<Type, 3, 1>::UnitY()) *
123 Eigen::AngleAxis<Type>(euler[0], Eigen::Matrix<Type, 3, 1>::UnitX()));
134template <
typename Type>
146template <
typename Type>
158template <
typename Type>
170template <
typename Type>
Eigen::Quaternion< Type > eulerRpyToQuaternion(const Eigen::Matrix< Type, 3, 1 > &euler)
Converts RPY extrinsic Tait-Bryan Euler angles (YPR intrinsic) to quaternion.
Definition geometry.hpp:118
Type quaternionToRoll(const Eigen::Quaternion< Type > &q)
Convert quaternion to roll angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:147
Type degToRad(Type deg)
Converts degrees to radians.
Definition geometry.hpp:47
Type wrapPi(Type angle)
Wraps an angle to the range [-pi, pi).
Definition geometry.hpp:70
Eigen::Matrix< Type, 3, 1 > quaternionToEulerRpy(const Eigen::Quaternion< Type > &q)
Converts a quaternion to RPY extrinsic Tait-Bryan Euler angles (YPR intrinsic) XYZ axes correspond to...
Definition geometry.hpp:90
Type quaternionToPitch(const Eigen::Quaternion< Type > &q)
Convert quaternion to pitch angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:159
Type radToDeg(Type rad)
Converts radians to degrees.
Definition geometry.hpp:38
Type quaternionToYaw(const Eigen::Quaternion< Type > &q)
Convert quaternion to yaw angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:171