pub struct Matrix3x3 { /* private fields */ }Expand description
A 3×3 f32 matrix stored in row-major order.
use embedded_matrix::Matrix3x3;
let m = Matrix3x3::identity();
assert!((m.det() - 1.0).abs() < 1e-5);
assert!((m.trace() - 3.0).abs() < 1e-5);Implementations§
Source§impl Matrix3x3
impl Matrix3x3
Sourcepub const fn from_diagonal(d: [f32; 3]) -> Matrix3x3
pub const fn from_diagonal(d: [f32; 3]) -> Matrix3x3
Diagonal matrix.
Sourcepub fn get(&self, row: usize, col: usize) -> f32
pub fn get(&self, row: usize, col: usize) -> f32
Returns the element at row row and column col (zero-indexed).
§Panics
Panics if row or col is 3 or greater.
Sourcepub fn solve(&self, b: [f32; 3]) -> Result<[f32; 3], MatrixError>
pub fn solve(&self, b: [f32; 3]) -> Result<[f32; 3], MatrixError>
Solves the system A·x = b.
Computed as A⁻¹·b: same cost and singularity criterion as
inv. For multiple right-hand sides with the same
matrix, compute inv() only once.
use embedded_matrix::Matrix3x3;
let a = Matrix3x3::new([[1.0, 2.0, 3.0], [0.0, 1.0, 4.0], [5.0, 6.0, 0.0]]);
let x = a.solve([1.0, 2.0, 3.0]).unwrap();
assert!((x[0] - 27.0).abs() < 1e-3);
assert!((x[1] + 22.0).abs() < 1e-3);
assert!((x[2] - 6.0).abs() < 1e-3);§Errors
MatrixError::SingularMatrix: same criterion asinv.MatrixError::NonFiniteValue: NaN / ±∞ in the matrix orb, or overflow.
Sourcepub fn approx_eq(&self, other: &Matrix3x3, tol: f32) -> bool
pub fn approx_eq(&self, other: &Matrix3x3, tol: f32) -> bool
Compares two matrices element-wise with an absolute tolerance.
Returns false if an element is NaN.
Sourcepub fn inv(&self) -> Result<Matrix3x3, MatrixError>
pub fn inv(&self) -> Result<Matrix3x3, MatrixError>
Inverse using the cofactor method (adjugate matrix / determinant).
§Errors
MatrixError::SingularMatrixif|det|is negligible compared to the sum of the absolute values of the determinant terms (relative threshold; see the crate documentation).MatrixError::NonFiniteValueif the matrix contains NaN / ±∞ or the calculation overflows.
Trait Implementations§
Source§impl AddAssign for Matrix3x3
impl AddAssign for Matrix3x3
Source§fn add_assign(&mut self, rhs: Matrix3x3)
fn add_assign(&mut self, rhs: Matrix3x3)
Performs the
+= operation. Read moreimpl Copy for Matrix3x3
Source§impl MulAssign for Matrix3x3
impl MulAssign for Matrix3x3
Source§fn mul_assign(&mut self, rhs: Matrix3x3)
fn mul_assign(&mut self, rhs: Matrix3x3)
Performs the
*= operation. Read moreSource§impl MulAssign<f32> for Matrix3x3
impl MulAssign<f32> for Matrix3x3
Source§fn mul_assign(&mut self, s: f32)
fn mul_assign(&mut self, s: f32)
Performs the
*= operation. Read moreimpl StructuralPartialEq for Matrix3x3
Auto Trait Implementations§
impl Forget for Matrix3x3
impl Freeze for Matrix3x3
impl Move for Matrix3x3
impl RefUnwindSafe for Matrix3x3
impl Send for Matrix3x3
impl Sync for Matrix3x3
impl Unpin for Matrix3x3
impl UnsafeUnpin for Matrix3x3
impl UnwindSafe for Matrix3x3
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more