pub fn inverse(&self) -> Matrix3 {
        let determinant = self.determinant();
        assert!(determinant.abs() > 1e-30, "The matrix is not invertible!");
        let inverse_determinant = 1.0 / determinant;
        let mut res = Matrix3::zero();
        res[0][0] = (self[1][1] * self[2][2] - self[2][1] * self[1][2]) * inverse_determinant;
        res[0][1] = (self[0][2] * self[2][1] - self[0][1] * self[2][2]) * inverse_determinant;
        res[0][2] = (self[0][1] * self[1][2] - self[0][2] * self[1][1]) * inverse_determinant;
        res[1][0] = (self[1][2] * self[2][0] - self[1][0] * self[2][2]) * inverse_determinant;
        res[1][1] = (self[0][0] * self[2][2] - self[0][2] * self[2][0]) * inverse_determinant;
        res[1][2] = (self[1][0] * self[0][2] - self[0][0] * self[1][2]) * inverse_determinant;
        res[2][0] = (self[1][0] * self[2][1] - self[2][0] * self[1][1]) * inverse_determinant;
        res[2][1] = (self[2][0] * self[0][1] - self[0][0] * self[2][1]) * inverse_determinant;
        res[2][2] = (self[0][0] * self[1][1] - self[1][0] * self[0][1]) * inverse_determinant;
        return res;
    }
/// Computes the inverse of a matrix
///
/// # Examples
///
/// ```
/// # use lumol_core::types::Matrix3;
/// // A diagonal matrix is trivially invertible
/// let matrix = Matrix3::new([
///     [4.0, 0.0, 0.0],
///     [0.0, 1.0, 0.0],
///     [0.0, 0.0, 7.0]
/// ]);
///
/// let inverted = Matrix3::new([
///     [1.0/4.0, 0.0, 0.0],
///     [0.0, 1.0, 0.0],
///     [0.0, 0.0, 1.0/7.0]
/// ]);
///
/// assert_eq!(matrix.inverse(), inverted);
/// assert_eq!(matrix * matrix.inverse(), Matrix3::one());
/// ```
///
/// # Panics
///
/// If the matrix is not invertible, *i.e.* if the matrix determinant
/// equals zero.
Computes the inverse of a matrix
Computes the inverse of a matrix
pub fn inverse(&self) -> Matrix3 {
        let determinant = self.determinant();
        assert!(determinant.abs() > 1e-30, "The matrix is not invertible!");
        let inverse_determinant = 1.0 / determinant;
        let mut res = Matrix3::zero();
        res[0][0] = (self[1][1] * self[2][2] - self[2][1] * self[1][2]) * inverse_determinant;
        res[0][1] = (self[0][2] * self[2][1] - self[0][1] * self[2][2]) * inverse_determinant;
        res[0][2] = (self[0][1] * self[1][2] - self[0][2] * self[1][1]) * inverse_determinant;
        res[1][0] = (self[1][2] * self[2][0] - self[1][0] * self[2][2]) * inverse_determinant;
        res[1][1] = (self[0][0] * self[2][2] - self[0][2] * self[2][0]) * inverse_determinant;
        res[1][2] = (self[1][0] * self[0][2] - self[0][0] * self[1][2]) * inverse_determinant;
        res[2][0] = (self[1][0] * self[2][1] - self[2][0] * self[1][1]) * inverse_determinant;
        res[2][1] = (self[2][0] * self[0][1] - self[0][0] * self[2][1]) * inverse_determinant;
        res[2][2] = (self[0][0] * self[1][1] - self[1][0] * self[0][1]) * inverse_determinant;
        return res;
    }
pub fn inverse ( & self ) -> Matrix3 { let determinant = self . determinant ( ) ; assert ! ( determinant abs ( ) 1e-30 " " ) ; let inverse_determinant = 1.0 / determinant ; let mut res = Matrix3 :: zero ( ) ; res [ 0 ] [ 0 ] = ( self [ 1 ] [ 1 ] * self [ 2 ] [ 2 ] - self [ 2 ] [ 1 ] * self [ 1 ] [ 2 ] ) * inverse_determinant ; res [ 0 ] [ 1 ] = ( self [ 0 ] [ 2 ] * self [ 2 ] [ 1 ] - self [ 0 ] [ 1 ] * self [ 2 ] [ 2 ] ) * inverse_determinant ; res [ 0 ] [ 2 ] = ( self [ 0 ] [ 1 ] * self [ 1 ] [ 2 ] - self [ 0 ] [ 2 ] * self [ 1 ] [ 1 ] ) * inverse_determinant ; res [ 1 ] [ 0 ] = ( self [ 1 ] [ 2 ] * self [ 2 ] [ 0 ] - self [ 1 ] [ 0 ] * self [ 2 ] [ 2 ] ) * inverse_determinant ; res [ 1 ] [ 1 ] = ( self [ 0 ] [ 0 ] * self [ 2 ] [ 2 ] - self [ 0 ] [ 2 ] * self [ 2 ] [ 0 ] ) * inverse_determinant ; res [ 1 ] [ 2 ] = ( self [ 1 ] [ 0 ] * self [ 0 ] [ 2 ] - self [ 0 ] [ 0 ] * self [ 1 ] [ 2 ] ) * inverse_determinant ; res [ 2 ] [ 0 ] = ( self [ 1 ] [ 0 ] * self [ 2 ] [ 1 ] - self [ 2 ] [ 0 ] * self [ 1 ] [ 1 ] ) * inverse_determinant ; res [ 2 ] [ 1 ] = ( self [ 2 ] [ 0 ] * self [ 0 ] [ 1 ] - self [ 0 ] [ 0 ] * self [ 2 ] [ 1 ] ) * inverse_determinant ; res [ 2 ] [ 2 ] = ( self [ 0 ] [ 0 ] * self [ 1 ] [ 1 ] - self [ 1 ] [ 0 ] * self [ 0 ] [ 1 ] ) * inverse_determinant ; return res ; }
Computes the inverse of a matrix
Computes the inverse of a matrix
&self
examples
None
use lumol_core::types::matrix3;
None
panics
If the matrix is not invertible, *i.e.* if the matrix determinant
equals zero.
If the matrix is not invertible * i . e . * if the matrix determinant equals zero .