2021-08-08 18:59:40 +08:00
|
|
|
use na::{Unit, UnitQuaternion};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::aliases::{Qua, TVec3};
|
2021-08-08 18:59:40 +08:00
|
|
|
use crate::RealNumber;
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The rotation angle of this quaternion assumed to be normalized.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn quat_angle<T: RealNumber>(x: &Qua<T>) -> T {
|
2018-09-20 20:23:31 +08:00
|
|
|
UnitQuaternion::from_quaternion(*x).angle()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Creates a quaternion from an axis and an angle.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn quat_angle_axis<T: RealNumber>(angle: T, axis: &TVec3<T>) -> Qua<T> {
|
2018-12-29 19:12:56 +08:00
|
|
|
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// The rotation axis of a quaternion assumed to be normalized.
|
2021-08-08 18:59:40 +08:00
|
|
|
pub fn quat_axis<T: RealNumber>(x: &Qua<T>) -> TVec3<T> {
|
2018-09-20 20:23:31 +08:00
|
|
|
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
|
2018-12-29 19:12:56 +08:00
|
|
|
a.into_inner()
|
2018-09-20 20:23:31 +08:00
|
|
|
} else {
|
2018-09-23 20:41:56 +08:00
|
|
|
TVec3::zeros()
|
2018-09-20 20:23:31 +08:00
|
|
|
}
|
2018-10-22 04:11:27 +08:00
|
|
|
}
|