Type Alias munum::Mat3

source ·
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>

source

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);
source

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.]);
source

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<Matrix<T, 2, 2>> for Mat3<T>

source§

fn from(m: Mat2<T>) -> Self

Augments a Mat2 into a Mat3 The resulting Mat3 contains the given Mat2 on upper-left with the lower-right element = 1.

§Examples
let m = Mat3::from(Mat2::<i32>::from_slice(&[2, 3, 4, 5]));
assert_eq!(*m.as_ref(), [2, 3, 0, 4, 5, 0, 0, 0, 1]);
source§

impl<T: Copy + NumAssign> From<Matrix<T, 4, 4>> for Mat3<T>

source§

fn from(m: Mat4<T>) -> Self

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]);
source§

impl<T: Copy + NumAssign> From<Quaternion<T>> for Mat3<T>

source§

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.]);