pub type Mat3<T = f32> = Matrix<T, 3, 3>;
Expand description
A 3x3 matrix
Aliased Type§
struct Mat3<T = f32>(/* private fields */);
Implementations§
source§impl<T: Copy + NumAssign> Mat3<T>
impl<T: Copy + NumAssign> Mat3<T>
sourcepub fn det(&self) -> T
pub fn det(&self) -> T
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);
sourcepub fn invert(&mut self) -> bool
pub fn invert(&mut self) -> bool
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.]);
sourcepub fn normal_matrix(&mut self) -> bool
pub fn normal_matrix(&mut self) -> bool
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§
source§impl<T: Copy + NumAssign> From<Quaternion<T>> for Mat3<T>
impl<T: Copy + NumAssign> From<Quaternion<T>> for Mat3<T>
source§fn from(q: Quaternion<T>) -> Self
fn from(q: Quaternion<T>) -> Self
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.]);