nalgebra/nalgebra-glm/src/quat/quaternion_trigonometric.rs

22 lines
685 B
Rust
Raw Normal View History

use na::{Real, U3, Unit, UnitQuaternion, Vector3};
use aliases::{Vec, Qua};
/// The rotation angle of this quaternion assumed to be normalized.
pub fn angle<N: Real>(x: &Qua<N>) -> N {
UnitQuaternion::from_quaternion(*x).angle()
}
/// Creates a quaternion from an axis and an angle.
pub fn angle_axis<N: Real>(angle: N, axis: &Vec<N, U3>) -> Qua<N> {
UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
}
/// The rotation axis of a quaternion assumed to be normalized.
pub fn axis<N: Real>(x: &Qua<N>) -> Vec<N, U3> {
if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() {
a.unwrap()
} else {
Vector3::zeros()
}
}