diff --git a/src/base/matrix.rs b/src/base/matrix.rs index fcd53703..78b82ec5 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -1480,6 +1480,19 @@ impl> Unit> { /// Computes the spherical linear interpolation between two unit vectors. + /// + /// # Examples: + /// + /// ``` + /// # use nalgebra::geometry::UnitQuaternion; + /// + /// let q1 = UnitQuaternion::from_euler_angles(std::f32::consts::FRAC_PI_4, 0.0, 0.0); + /// let q2 = UnitQuaternion::from_euler_angles(-std::f32::consts::PI, 0.0, 0.0); + /// + /// let q = q1.slerp(&q2, 1.0 / 3.0); + /// + /// assert_eq!(q.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); + /// ``` pub fn slerp>( &self, rhs: &Unit>, @@ -1513,7 +1526,7 @@ impl> Unit> { return Some(Unit::new_unchecked(self.clone_owned())); } - let hang = c_hang.acos(); + let hang = c_hang.abs().acos(); let s_hang = (N::one() - c_hang * c_hang).sqrt(); // FIXME: what if s_hang is 0.0 ? The result is not well-defined. @@ -1522,7 +1535,7 @@ impl> Unit> { } else { let ta = ((N::one() - t) * hang).sin() / s_hang; let tb = (t * hang).sin() / s_hang; - let res = &**self * ta + &**rhs * tb; + let res = &**self * ta + &**rhs * tb * c_hang.signum(); Some(Unit::new_unchecked(res)) }