Struct Matrix4

Source
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>

Source

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 matrix
  • row2 - A 4 element array representing the second row of the matrix
  • row3 - A 4 element array representing the third row of the matrix
  • row4 - A 4 element array representing the fourth row of the matrix
Source

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

Source

pub fn identity() -> Self
where T: Zero + One,

one: T equivalent of one zero: T equivalent of zero

Source

pub fn determinant(&self) -> T
where T: Add<T, Output = T> + Mul<T, Output = T> + Sub<T, Output = T> + Copy,

Source

pub fn transpose(&self) -> Matrix4<T>
where T: Copy,

Source

pub fn cofactor(self) -> Self
where T: Mul<T, Output = T> + Neg<Output = T> + Add<T, Output = T> + Sub<T, Output = T> + Copy,

Source

pub fn adjugate(self) -> Self
where T: Mul<T, Output = T> + Neg<Output = T> + Add<T, Output = T> + Sub<T, Output = T> + Copy,

Get the adjugate matrix of a 3x3 matrix.

Source

pub fn inverse(&self) -> Matrix4<T>
where T: Add<T, Output = T> + Mul<T, Output = T> + Sub<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + Copy,

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>
where T: Add<T, Output = T> + Copy,

Source§

fn add(self, rhs: T) -> Self::Output

Matrix4 + T = 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§

type Output = Matrix4<T>

The resulting type after applying the + operator.
Source§

impl<T> Add for Matrix4<T>
where T: Add<T, Output = T> + Copy,

Source§

fn add(self, rhs: Self) -> Self::Output

Matrix4 + T = 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§

type Output = Matrix4<T>

The resulting type after applying the + operator.
Source§

impl<T: Clone> Clone for Matrix4<T>

Source§

fn clone(&self) -> Matrix4<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Matrix4<T>
where T: Debug + Copy,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Div<T> for Matrix4<T>
where T: Div<T, Output = T> + Copy,

Source§

fn div(self, rhs: T) -> Self::Output

Matrix4 / T = 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§

type Output = Matrix4<T>

The resulting type after applying the / operator.
Source§

impl<T> Div for Matrix4<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + Copy,

Source§

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§

type Output = Matrix4<T>

The resulting type after applying the / operator.
Source§

impl<T> F32Fmt for Matrix4<T>
where T: F32Fmt + Copy,

Source§

type F32Fmt = Matrix4<<T as F32Fmt>::F32Fmt>

Source§

fn intoF32Fmt(self) -> Self::F32Fmt

Source§

fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn cbrt(self) -> Self

Source§

fn f32_const_mul(self, constant: f32) -> Self

Source§

fn sin_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cos_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tan_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn asin_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn acos_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn sinh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cosh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tanh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

impl<T> From<Matrix3<T>> for Matrix4<T>
where T: One + Zero + Copy,

Source§

fn from(mat3: Matrix3<T>) -> Matrix4<T>

Converts to this type from the input type.
Source§

impl<T> From<Matrix4<T>> for [[T; 4]; 4]

Source§

fn from(other: Matrix4<T>) -> [[T; 4]; 4]

Converts to this type from the input type.
Source§

impl<T> Mul<T> for Matrix4<T>
where T: Mul<T, Output = T> + Copy,

Source§

fn mul(self, rhs: T) -> Self::Output

Matrix4 * T = 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§

type Output = Matrix4<T>

The resulting type after applying the * operator.
Source§

impl<T> Mul<Vector4<T>> for Matrix4<T>
where T: Add<T, Output = T> + Mul<T, Output = T> + Copy,

Source§

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§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

impl<T> Mul for Matrix4<T>
where T: Add<T, Output = T> + Mul<T, Output = T> + Copy,

Source§

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§

type Output = Matrix4<T>

The resulting type after applying the * operator.
Source§

impl<T> Neg for Matrix4<T>
where T: Neg<Output = T> + Copy,

Source§

fn neg(self) -> Self::Output

-Matrix4 = 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§

type Output = Matrix4<T>

The resulting type after applying the - operator.
Source§

impl<T> One for Matrix4<T>
where T: Zero + One,

Source§

const ONE: Self

The identity matrix

Source§

impl<T: PartialEq> PartialEq for Matrix4<T>

Source§

fn eq(&self, other: &Matrix4<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Rem<T> for Matrix4<T>
where T: Rem<T, Output = T> + Copy,

Source§

fn rem(self, rhs: T) -> Self::Output

Matrix4 % T = 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§

type Output = Matrix4<T>

The resulting type after applying the % operator.
Source§

impl<T> Rem for Matrix4<T>
where T: Rem<T, Output = T> + Copy,

Source§

fn rem(self, rhs: Self) -> Self::Output

Matrix4 % Matrix4 = Matrix4 Finds the remainder after an ELEMENT WISE division

§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§

type Output = Matrix4<T>

The resulting type after applying the % operator.
Source§

impl<T> SignOps for Matrix4<T>

Source§

fn ptcopysign(self, _sign: Self) -> Self

Source§

fn ptsignum(self) -> i8

Source§

fn abs(self) -> Self

Source§

impl<T> Sub<T> for Matrix4<T>
where T: Sub<T, Output = T> + Copy,

Source§

fn sub(self, rhs: T) -> Self::Output

Matrix4 - T = 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§

type Output = Matrix4<T>

The resulting type after applying the - operator.
Source§

impl<T> Sub for Matrix4<T>
where T: Sub<T, Output = T> + Copy,

Source§

fn sub(self, rhs: Self) -> Self::Output

Matrix4 - T = 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);
Source§

type Output = Matrix4<T>

The resulting type after applying the - operator.
Source§

impl<T> Two for Matrix4<T>
where T: Zero + Two,

Source§

const TWO: Self

The identity matrix

Source§

impl<T> Zero for Matrix4<T>
where T: Zero + Copy,

Source§

const ZERO: Self

Source§

impl<T> Construct<T> for Matrix4<T>
where T: Construct<T>,

Source§

impl<T: Copy> Copy for Matrix4<T>

Source§

impl<T> SqMatrix<T, Vector4<T>> for Matrix4<T>
where T: Construct<T>,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, A> Typed<T> for A
where T: Construct<A>,