pub struct Matrix2x2 {
pub r1: Vector2,
pub r2: Vector2,
}
Expand description
Implements a matrix 2 x 2
Fields§
§r1: Vector2
§r2: Vector2
Implementations§
Source§impl Matrix2x2
impl Matrix2x2
Sourcepub fn IDENTITY() -> Self
pub fn IDENTITY() -> Self
Identity Matrrix NxN, where all elements Uij that i = j are 1
// | 1 0 |
// | 0 1 |
Sourcepub fn det(&self) -> f32
pub fn det(&self) -> f32
Matrix determinant
// | 4 -3 |
// let matrix = | 0 2 |
// matrix.det() = 2
use mathf::matrix::{Matrix2x2};
let matrix = Matrix2x2::new_idx(4.0, -3.0, 0.0, 2.0);
assert_eq!(matrix.det(), 8f32);
Sourcepub fn vectorize(&self) -> Vec<Vec<f32>>
pub fn vectorize(&self) -> Vec<Vec<f32>>
Transforms a MatrixNxN into a Vec<Vec
// | 4 -3 |`
// let matrix = | 0 2 |`
// matrix.det() = 2
use mathf::matrix::{Matrix2x2};
let matrix = Matrix2x2::new_idx(4.0, -3.0, 0.0, 2.0);
assert_eq!(matrix.vectorize(), vec![
vec![4.0, -3.0], vec![0.0, 2.0]
]);
Sourcepub fn inverse(&self, delta: f32) -> Result<Matrix2x2, Error>
pub fn inverse(&self, delta: f32) -> Result<Matrix2x2, Error>
Matrix inverse
// | 4 7 |
// let matrix = | 2 6 |
//
// | 6 -7 |
// let matrix_inverse = 1/10 | -2 4 |
use mathf::matrix::{Matrix2x2};
let matrix = Matrix2x2::new_idx(4.0, 7.0, 2.0, 6.0);
let matrix_inverse = Matrix2x2::new_idx(0.6, -0.7, -0.2, 0.4);
assert_eq!(matrix.inverse(0.001).unwrap(), matrix_inverse);
Sourcepub fn is_orthogonal(&self) -> bool
pub fn is_orthogonal(&self) -> bool
A matrix is orthogonal if and only if transpose(A) == inverse(A)
Sourcepub fn scale_matrix(a: f32) -> Self
pub fn scale_matrix(a: f32) -> Self
// | a 0 |
// | 0 a |
Sourcepub fn new_idx(n1: f32, n2: f32, n3: f32, n4: f32) -> Matrix2x2
pub fn new_idx(n1: f32, n2: f32, n3: f32, n4: f32) -> Matrix2x2
Creates a new Matrix2x2 from 4 indexed floats
pub fn scale_matrix_non_uniform(a: f32, b: f32) -> Self
Sourcepub fn rotation_2d(teta: f32) -> Self
pub fn rotation_2d(teta: f32) -> Self
2D rotation Matrix by angle teta (radians) For matrix 2x2:
// P′= | cosθ − sinθ | P
// | sinθ + cosθ |
Trait Implementations§
impl StructuralPartialEq for Matrix2x2
Auto Trait Implementations§
impl Freeze for Matrix2x2
impl RefUnwindSafe for Matrix2x2
impl Send for Matrix2x2
impl Sync for Matrix2x2
impl Unpin for Matrix2x2
impl UnwindSafe for Matrix2x2
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