2018-09-20 20:23:31 +08:00
|
|
|
use na::{Real, U3, UnitQuaternion, Unit};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
|
|
|
use aliases::{Vec, Qua};
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Computes the quaternion exponential.
|
2018-09-20 16:50:34 +08:00
|
|
|
pub fn 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-20 16:50:34 +08:00
|
|
|
pub fn 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-20 16:50:34 +08:00
|
|
|
pub fn 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-20 16:50:34 +08:00
|
|
|
pub fn rotate<N: Real>(q: &Qua<N>, angle: N, axis: &Vec<N, U3>) -> 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 19:18:59 +08:00
|
|
|
//pub fn sqrt<N: Real>(q: &Qua<N>) -> Qua<N> {
|
|
|
|
// unimplemented!()
|
|
|
|
//}
|