Type Definition munum::Mat3

source · []
pub type Mat3<T = f32> = Matrix<T, 3, 3>;
Expand description

A 3x3 matrix

Implementations

Calculates the determinant of this matrix.

Examples
let m = Mat3::<i32>::from_slice(&[1, 0, 5, 2, 1, 6, 3, 4, 0]);
assert_eq!(m.det(), 1);

Invert this matrix. If this matrix is not invertible, this method returns false and the matrix is unchanged. For formula, see: https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3_%C3%97_3_matrices

Examples
let mut m = <Mat3>::from_slice(&[1., 0., 5., 2., 1., 6., 3., 4., 0.]);
assert!(m.invert());
assert_eq!(*m.as_ref(), [-24., 20., -5., 18., -15., 4., 5., -4., 1.]);

let mut m2 = <Mat3>::from_slice(&[1., 0., 1., 0., 1., 0., 0., 0., 0.]);
assert!(!m2.invert());
assert_eq!(*m2.as_ref(), [1., 0., 1., 0., 1., 0., 0., 0., 0.]);

Transforms this matrix into a normal matrix, which is the inverse transpose of itself. If this matrix is not invertible, this method returns false and the matrix is unchanged.

Examples
let mut m = <Mat3>::from_slice(&[0., 0., 1., 1., 0., 0., 0., 1., 0.]);
assert!(m.normal_matrix());
assert_eq!(*m.as_ref(), [0., 0., 1., 1., 0., 0., 0., 1., 0.]);

Trait Implementations

Creates a Mat3 from the upper-left 3x3 of a Mat4

Examples
let m = Mat3::from(Mat4::<i32>::from_slice(&[2, 3, 4, 11, 5, 6, 7, 12, 8, 9, 10, 13, 14, 15, 0, 1]));
assert_eq!(*m.as_ref(), [2, 3, 4, 5, 6, 7, 8, 9, 10]);

Converts a Quaternion into a Mat3

Examples
let ONE_OVER_SQRT3: f32 = 1. / 3_f32.sqrt();
let m = <Mat3>::from(<Quaternion>::from_slice(&[ONE_OVER_SQRT3, ONE_OVER_SQRT3, ONE_OVER_SQRT3, 0.]));
assert_float_eq!(m.as_ref(), &[-1./3., 2./3., 2./3., 2./3., -1./3., 2./3., 2./3., 2./3., -1./3.]);