pub struct Matrix4<T> {
pub m: [[T; 4]; 4],
}
Expand description
A 4x4 matrix with row major order.
Fields§
§m: [[T; 4]; 4]
Implementations§
Source§impl<T> Matrix4<T>
impl<T> Matrix4<T>
Sourcepub fn new(row0: [T; 4], row1: [T; 4], row2: [T; 4], row3: [T; 4]) -> Self
pub fn new(row0: [T; 4], row1: [T; 4], row2: [T; 4], row3: [T; 4]) -> Self
A cleaner way of making a new Matrix4.
Returns a new Matrix4
§Arguments
row0
- A 4 element array representing the first row of the matrixrow2
- A 4 element array representing the second row of the matrixrow3
- A 4 element array representing the third row of the matrixrow4
- A 4 element array representing the fourth row of the matrix
pub fn new_val( r0c0: T, r0c1: T, r0c2: T, r0c3: T, r1c0: T, r1c1: T, r1c2: T, r1c3: T, r2c0: T, r2c1: T, r2c2: T, r2c3: T, r3c0: T, r3c1: T, r3c2: T, r3c3: T, ) -> Self
pub fn determinant(&self) -> T
pub fn transpose(&self) -> Matrix4<T>where
T: Copy,
pub fn cofactor(self) -> Self
Sourcepub fn inverse(&self) -> Matrix4<T>
pub fn inverse(&self) -> Matrix4<T>
Get the inverse of a 4x4 matrix.
§Arguments
self
- The matrix the function is being called for
Inserts a value computed from f
into the option if it is None
, then
returns a mutable reference to the contained value.
§Examples
use feo_math::linear_algebra::matrix4::Matrix4;
let x = Matrix4::new(
[1.0,12.0,13.0,14.0],
[21.0,2.0,23.0,24.0],
[31.0,32.0,3.0,34.0],
[41.0,42.0,43.0,4.0]);
let x_inverse = x.inverse();
assert_eq!(x_inverse, Matrix4::new(
[-57.0/932.0,17.0/932.0,53.0/4660.0,37.0/4660.0],
[139.0/4660.0,-8.0/233.0,51.0/4660.0,2.0/233.0],
[25.0/932.0,69.0/4660.0,-21.0/932.0,41.0/4660.0],
[59.0/2330.0,67.0/4660.0,5.0/466.0,-15.0/932.0])); // TODO is this transposed should not be !!!!!!!!!!!!!!!
Trait Implementations§
Source§impl<T> Add<T> for Matrix4<T>
impl<T> Add<T> for Matrix4<T>
Source§fn add(self, rhs: T) -> Self::Output
fn add(self, rhs: T) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let val = 2;
let expected = Matrix4::new(
[3, 4, 5, 6],
[5, 6, 3, 4],
[6, 3, 4, 5],
[4, 5, 6, 3]
);
assert_eq!(mat + val, expected);
Source§impl<T> Add for Matrix4<T>
impl<T> Add for Matrix4<T>
Source§fn add(self, rhs: Self) -> Self::Output
fn add(self, rhs: Self) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat0 = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let mat1 = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 2, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let expected = Matrix4::new(
[2, 4, 6, 8],
[6, 8, 3, 4],
[8, 2, 4, 6],
[4, 6, 8, 2]
);
assert_eq!(mat0 + mat1, expected);
Source§impl<T> Div<T> for Matrix4<T>
impl<T> Div<T> for Matrix4<T>
Source§fn div(self, rhs: T) -> Self::Output
fn div(self, rhs: T) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let val = 2;
let expected = Matrix4::new(
[0, 1, 1, 2],
[1, 2, 0, 1],
[2, 0, 1, 1],
[1, 1, 2, 0]
);
assert_eq!(mat / val, expected);
Source§impl<T> Div for Matrix4<T>
impl<T> Div for Matrix4<T>
Source§fn div(self, rhs: Self) -> Self::Output
fn div(self, rhs: Self) -> Self::Output
§Examples
use feo_math::linear_algebra::vector4::Vector4;
use feo_math::linear_algebra::matrix4::Matrix4;
let mat0 = Matrix4::new(
[4, 5, 6, 0],
[6, 4, 5, 0],
[5, 6, 4, 0],
[0, 0, 0, 1],
);
let mat1 = Matrix4::new(
[1, 2, 3, 0],
[2, 3, 1, 0],
[3, 1, 2, 0],
[0, 0, 0, 1]
);
let expected = Matrix4::new(
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
);
assert_eq!(mat0 / mat1, expected);
Source§impl<T> F32Fmt for Matrix4<T>
impl<T> F32Fmt for Matrix4<T>
type F32Fmt = Matrix4<<T as F32Fmt>::F32Fmt>
fn intoF32Fmt(self) -> Self::F32Fmt
fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self
fn sqrt(self) -> Self
fn cbrt(self) -> Self
fn f32_const_mul(self, constant: f32) -> Self
fn sin_mul(self, _mul_by: Self) -> Self
fn cos_mul(self, _mul_by: Self) -> Self
fn tan_mul(self, _mul_by: Self) -> Self
fn asin_mul(self, _mul_by: Self) -> Self
fn acos_mul(self, _mul_by: Self) -> Self
fn atan_mul(self, _mul_by: Self) -> Self
fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
fn sinh_mul(self, _mul_by: Self) -> Self
fn cosh_mul(self, _mul_by: Self) -> Self
fn tanh_mul(self, _mul_by: Self) -> Self
Source§impl<T> Mul<T> for Matrix4<T>
impl<T> Mul<T> for Matrix4<T>
Source§fn mul(self, rhs: T) -> Self::Output
fn mul(self, rhs: T) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let val = 2;
let expected = Matrix4::new(
[2, 4, 6, 8],
[6, 8, 2, 4],
[8, 2, 4, 6],
[4, 6, 8, 2]
);
assert_eq!(mat * val, expected);
Source§impl<T> Mul<Vector4<T>> for Matrix4<T>
impl<T> Mul<Vector4<T>> for Matrix4<T>
Source§fn mul(self, rhs: Vector4<T>) -> Self::Output
fn mul(self, rhs: Vector4<T>) -> Self::Output
Matrix4 * Vec3d = type Vec3d
§Examples
use feo_math::linear_algebra::vector4::Vector4;
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let vec = Vector4::new(1, 4, 2, 3);
assert_eq!(mat * vec, Vector4::new(27, 27, 21, 25));
Source§impl<T> Mul for Matrix4<T>
impl<T> Mul for Matrix4<T>
Source§fn mul(self, rhs: Self) -> Self::Output
fn mul(self, rhs: Self) -> Self::Output
Matrix4 * Matrix4 = Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat0 = Matrix4::new(
[4, 6, 6, 0],
[6, 4, 5, 0],
[5, 6, 4, 0],
[0, 0, 0, 1]
);
let mat1 = Matrix4::new(
[1, 2, 3, 0],
[2, 3, 1, 0],
[2, 1, 2, 0],
[0, 0, 0, 1]
);
let expected = Matrix4::new(
[28, 32, 30, 0],
[24, 29, 32, 0],
[25, 32, 29, 0],
[0, 0, 0, 1]
);
assert_eq!(mat0 * mat1, expected);
Source§impl<T> Neg for Matrix4<T>
impl<T> Neg for Matrix4<T>
Source§fn neg(self) -> Self::Output
fn neg(self) -> Self::Output
-Matrix4
§Examples
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let expected = Matrix4::new(
[-1, -2, -3, -4],
[-3, -4, -1, -2],
[-4, -1, -2, -3],
[-2, -3, -4, -1]
);
assert_eq!(-mat, expected);
Source§impl<T> Rem<T> for Matrix4<T>
impl<T> Rem<T> for Matrix4<T>
Source§fn rem(self, rhs: T) -> Self::Output
fn rem(self, rhs: T) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let val = 2;
let expected = Matrix4::new(
[1, 0, 1, 0],
[1, 0, 1, 0],
[0, 1, 0, 1],
[0, 1, 0, 1]
);
assert_eq!(mat % val, expected);
ⓘ
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
mat % 0;
Source§impl<T> Rem for Matrix4<T>
impl<T> Rem for Matrix4<T>
Source§fn rem(self, rhs: Self) -> Self::Output
fn rem(self, rhs: Self) -> Self::Output
Matrix4
§Examples
use feo_math::linear_algebra::matrix4::Matrix4;
let mat0 = Matrix4::new(
[4, 5, 6, 3],
[6, 4, 5, 2],
[5, 6, 4, 1],
[8, 1, 3, 2],
);
let mat1 = Matrix4::new(
[1, 2, 3, 4],
[2, 3, 1, 5],
[3, 1, 2, 6],
[3, 9, 8, 7],
);
let expected = Matrix4::new(
[0, 1, 0, 3],
[0, 1, 0, 2],
[2, 0, 0, 1],
[2, 1, 3, 2],
);
assert_eq!(mat0 % mat1, expected);
Source§impl<T> Sub<T> for Matrix4<T>
impl<T> Sub<T> for Matrix4<T>
Source§fn sub(self, rhs: T) -> Self::Output
fn sub(self, rhs: T) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let val = 2;
let expected = Matrix4::new(
[-1, 0, 1, 2],
[ 1, 2, -1, 0],
[ 2, -1, 0, 1],
[ 0, 1, 2, -1]
);
assert_eq!(mat - val, expected);
Source§impl<T> Sub for Matrix4<T>
impl<T> Sub for Matrix4<T>
Source§fn sub(self, rhs: Self) -> Self::Output
fn sub(self, rhs: Self) -> Self::Output
Matrix4
use feo_math::linear_algebra::matrix4::Matrix4;
let mat0 = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 1, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let mat1 = Matrix4::new(
[1, 2, 3, 4],
[3, 4, 2, 2],
[4, 1, 2, 3],
[2, 3, 4, 1]
);
let expected = Matrix4::new(
[0, 0, 0, 0],
[0, 0, -1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
);
assert_eq!(mat0 - mat1, expected);
impl<T> Construct<T> for Matrix4<T>where
T: Construct<T>,
impl<T: Copy> Copy for Matrix4<T>
impl<T> SqMatrix<T, Vector4<T>> for Matrix4<T>where
T: Construct<T>,
impl<T> StructuralPartialEq for Matrix4<T>
Auto Trait Implementations§
impl<T> Freeze for Matrix4<T>where
T: Freeze,
impl<T> RefUnwindSafe for Matrix4<T>where
T: RefUnwindSafe,
impl<T> Send for Matrix4<T>where
T: Send,
impl<T> Sync for Matrix4<T>where
T: Sync,
impl<T> Unpin for Matrix4<T>where
T: Unpin,
impl<T> UnwindSafe for Matrix4<T>where
T: UnwindSafe,
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