38template<
typename Type>
41 return rad *
static_cast<Type
>(180.0 / M_PI);
47template<
typename Type>
50 return deg *
static_cast<Type
>(M_PI / 180.0);
55static inline constexpr float operator"" _deg(
long double degrees)
57 return static_cast<float>(degrees * M_PI / 180.0);
59static inline constexpr float operator"" _rad(
long double radians)
61 return static_cast<float>(radians);
71template<
typename Type>
74 while (angle >= M_PI) {
77 while (angle < -M_PI) {
90template<
typename Type>
93 Eigen::Matrix<Type, 3, 1> angles;
94 Eigen::Matrix<Type, 3, 3> dcm = q.toRotationMatrix();
96 angles.y() = asin(-dcm.coeff(2, 0));
98 if ((std::fabs(angles.y() -
static_cast<Type
>(M_PI / 2))) <
static_cast<Type
>(1.0e-3)) {
100 angles.z() = atan2(dcm.coeff(1, 2), dcm.coeff(0, 2));
101 }
else if ((std::fabs(angles.y() +
static_cast<Type
>(M_PI / 2))) <
static_cast<Type
>(1.0e-3)) {
103 angles.z() = atan2(-dcm.coeff(1, 2), -dcm.coeff(0, 2));
105 angles.x() = atan2(dcm.coeff(2, 1), dcm.coeff(2, 2));
106 angles.z() = atan2(dcm.coeff(1, 0), dcm.coeff(0, 0));
118template<
typename Type>
121 return Eigen::Quaternion<Type>(
122 Eigen::AngleAxis<Type>(euler[2], Eigen::Matrix<Type, 3, 1>::UnitZ()) *
123 Eigen::AngleAxis<Type>(euler[1], Eigen::Matrix<Type, 3, 1>::UnitY()) *
124 Eigen::AngleAxis<Type>(euler[0], Eigen::Matrix<Type, 3, 1>::UnitX()));
135template<
typename Type>
147template<
typename Type>
155 return std::atan2(2.0 * (w * x + y * z), w * w - x * x - y * y + z * z);
164template<
typename Type>
172 return std::atan2(2.0 * (w * y - z * x), 1.0 - 2.0 * (x * x + y * y));
181template<
typename Type>
189 return std::atan2(2.0 * (x * y + w * z), w * w + x * x - y * y - z * z);
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:119
Type quaternionToRoll(const Eigen::Quaternion< Type > &q)
Convert quaternion to roll angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:148
Type degToRad(Type deg)
Converts degrees to radians.
Definition geometry.hpp:48
Type wrapPi(Type angle)
Wraps an angle to the range [-pi, pi).
Definition geometry.hpp:72
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:91
Type quaternionToPitch(const Eigen::Quaternion< Type > &q)
Convert quaternion to pitch angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:165
Type radToDeg(Type rad)
Converts radians to degrees.
Definition geometry.hpp:39
Type quaternionToYaw(const Eigen::Quaternion< Type > &q)
Convert quaternion to yaw angle in extrinsic RPY order (intrinsic YPR)
Definition geometry.hpp:182