2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, UnitQuaternion, Unit};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-23 20:41:56 +08:00
|
|
|
use aliases::{Qua, TVec3};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes the quaternion exponential.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_exp<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.exp()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes the quaternion logarithm.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_log<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.ln()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Raises the quaternion `q` to the power `y`.
|
2018-09-22 22:40:58 +08:00
|
|
|
pub fn quat_pow<N: Real>(q: &Qua<N>, y: N) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q.powf(y)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`.
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn quat_rotate<N: Real>(q: &Qua<N>, angle: N, axis: &TVec3<N>) -> Qua<N> {
|
2018-09-20 20:23:31 +08:00
|
|
|
q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap()
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
2018-09-20 20:23:31 +08:00
|
|
|
|
2018-09-22 22:40:58 +08:00
|
|
|
//pub fn quat_sqrt<N: Real>(q: &Qua<N>) -> Qua<N> {
|
2018-09-22 19:18:59 +08:00
|
|
|
// unimplemented!()
|
|
|
|
//}
|