mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 18:46:18 +00:00
aux/math: Add quat finite difference function
This commit is contained in:
parent
9004ea80bb
commit
d29dc04e05
|
@ -75,7 +75,7 @@ math_quat_rotate(const struct xrt_quat *left,
|
||||||
* Integrate an angular velocity vector (exponential map) and apply to a
|
* Integrate an angular velocity vector (exponential map) and apply to a
|
||||||
* quaternion.
|
* quaternion.
|
||||||
*
|
*
|
||||||
* velocity and dt should share the same units of time, and the angular velocity
|
* ang_vel and dt should share the same units of time, and the ang_vel
|
||||||
* vector should be in radians per unit of time.
|
* vector should be in radians per unit of time.
|
||||||
*
|
*
|
||||||
* @relates xrt_quat
|
* @relates xrt_quat
|
||||||
|
@ -86,6 +86,25 @@ math_quat_integrate_velocity(const struct xrt_quat *quat,
|
||||||
const struct xrt_vec3 *ang_vel,
|
const struct xrt_vec3 *ang_vel,
|
||||||
const float dt,
|
const float dt,
|
||||||
struct xrt_quat *result);
|
struct xrt_quat *result);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Compute an angular velocity vector (exponential map format) by taking the
|
||||||
|
* finite difference of two quaternions.
|
||||||
|
*
|
||||||
|
* quat1 is the orientation dt time after the orientation was quat0
|
||||||
|
*
|
||||||
|
* out_ang_vel and dt share the same units of time, and out_ang_vel is be in
|
||||||
|
* radians per unit of time.
|
||||||
|
*
|
||||||
|
* @relates xrt_quat
|
||||||
|
* @relatesalso xrt_vec3
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
math_quat_finite_difference(const struct xrt_quat *quat0,
|
||||||
|
const struct xrt_quat *quat1,
|
||||||
|
const float dt,
|
||||||
|
struct xrt_vec3 *out_ang_vel);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Pose functions.
|
* Pose functions.
|
||||||
|
|
|
@ -139,6 +139,7 @@ math_quat_integrate_velocity(const struct xrt_quat *quat,
|
||||||
assert(quat != NULL);
|
assert(quat != NULL);
|
||||||
assert(ang_vel != NULL);
|
assert(ang_vel != NULL);
|
||||||
assert(result != NULL);
|
assert(result != NULL);
|
||||||
|
assert(dt != 0);
|
||||||
|
|
||||||
|
|
||||||
Eigen::Quaternionf q = map_quat(*quat);
|
Eigen::Quaternionf q = map_quat(*quat);
|
||||||
|
@ -146,3 +147,20 @@ math_quat_integrate_velocity(const struct xrt_quat *quat,
|
||||||
quat_exp(map_vec3(*ang_vel) * dt * 0.5f).normalized();
|
quat_exp(map_vec3(*ang_vel) * dt * 0.5f).normalized();
|
||||||
map_quat(*result) = q * incremental_rotation;
|
map_quat(*result) = q * incremental_rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
math_quat_finite_difference(const struct xrt_quat *quat0,
|
||||||
|
const struct xrt_quat *quat1,
|
||||||
|
const float dt,
|
||||||
|
struct xrt_vec3 *out_ang_vel)
|
||||||
|
{
|
||||||
|
assert(quat0 != NULL);
|
||||||
|
assert(quat1 != NULL);
|
||||||
|
assert(out_ang_vel != NULL);
|
||||||
|
assert(dt != 0);
|
||||||
|
|
||||||
|
|
||||||
|
Eigen::Quaternionf inc_quat =
|
||||||
|
map_quat(*quat1) * map_quat(*quat0).conjugate();
|
||||||
|
map_vec3(*out_ang_vel) = 2.f * quat_ln(inc_quat);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue