a/math: Add math_quat_to_euler_angles

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2312>
This commit is contained in:
Christoph Haag 2024-08-26 18:18:56 +02:00 committed by Marge Bot
parent 7150279e2b
commit 71b5d37e7e
2 changed files with 19 additions and 0 deletions

View file

@ -222,6 +222,14 @@ math_quat_from_angle_vector(float angle_rads, const struct xrt_vec3 *vector, str
void
math_quat_from_euler_angles(const struct xrt_vec3 *angles, struct xrt_quat *result);
/*!
* Create a rotation from a quaternion to euler angles
* @relates xrt_quat
* @ingroup aux_math
*/
void
math_quat_to_euler_angles(const struct xrt_quat *quat, struct xrt_vec3 *euler_angles);
/*!
* Create a rotation from a 3x3 rotation (row major) matrix.
*

View file

@ -222,6 +222,17 @@ math_quat_from_euler_angles(const struct xrt_vec3 *angles, struct xrt_quat *resu
Eigen::AngleAxisf(angles->x, Eigen::Vector3f::UnitX());
}
extern "C" void
math_quat_to_euler_angles(const struct xrt_quat *quat, struct xrt_vec3 *euler_angles)
{
Eigen::Quaternionf eigen_quat(quat->w, quat->x, quat->y, quat->z);
Eigen::Vector3f eigen_euler = eigen_quat.toRotationMatrix().eulerAngles(2, 1, 0);
euler_angles->x = eigen_euler.x();
euler_angles->y = eigen_euler.y();
euler_angles->z = eigen_euler.z();
}
extern "C" void
math_quat_from_matrix_3x3(const struct xrt_matrix_3x3 *mat, struct xrt_quat *result)
{