Skip to content

Commit

Permalink
Merge pull request #815 from dimforge/isometry_inv_mul
Browse files Browse the repository at this point in the history
Add a dedicated method for computing isometry1.inverse() * isometry2.
  • Loading branch information
sebcrozet committed Dec 18, 2020
2 parents 8c61528 + 6070864 commit 3899d92
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/geometry/isometry.rs
Expand Up @@ -210,6 +210,28 @@ where
self.translation.vector = self.rotation.transform_vector(&self.translation.vector);
}

/// Computes `self.inverse() * rhs` in a more efficient way.
///
/// # Example
///
/// ```
/// # use std::f32;
/// # use nalgebra::{Isometry2, Point2, Vector2};
/// let mut iso1 = Isometry2::new(Vector2::new(1.0, 2.0), f32::consts::FRAC_PI_2);
/// let mut iso2 = Isometry2::new(Vector2::new(10.0, 20.0), f32::consts::FRAC_PI_4);
///
/// assert_eq!(iso1.inverse() * iso2, iso1.inv_mul(&iso2));
/// ```
#[inline]
pub fn inv_mul(&self, rhs: &Isometry<N, D, R>) -> Self {
let inv_rot1 = self.rotation.inverse();
let tr_12 = rhs.translation.vector.clone() - self.translation.vector.clone();
Isometry::from_parts(
inv_rot1.transform_vector(&tr_12).into(),
inv_rot1 * rhs.rotation.clone(),
)
}

/// Appends to `self` the given translation in-place.
///
/// # Example
Expand Down

0 comments on commit 3899d92

Please sign in to comment.