Mat3

Struct Mat3 

Source
pub struct Mat3 {
    pub a: f64,
    pub b: f64,
    pub c: f64,
    pub d: f64,
    pub e: f64,
    pub f: f64,
    pub g: f64,
    pub h: f64,
    pub i: f64,
}
Expand description

a 3×3 matrix of f64 values.

The matrix is stored in row-major order:

| a  b  c |
| c  d  e |
| g  h  i |

Fields§

§a: f64

First row, first column element.

§b: f64

First row, second column element.

§c: f64

First row, third column element.

§d: f64

Second row, first column element.

§e: f64

Second row, second column element.

§f: f64

Second row, third column element.

§g: f64

Third row, first column element.

§h: f64

Third row, second column element.

§i: f64

Third row, third column element.

Implementations§

Source§

impl Mat3

Source

pub const fn new( a: f64, b: f64, c: f64, d: f64, e: f64, f: f64, g: f64, h: f64, i: f64, ) -> Mat3

Source§

impl Mat3

Source

pub const IDENTITY: Mat3

The identity matrix:

| 1  0  0 |
| 0  1  0 |
| 0  0  1 |
Source

pub const ZERO: Mat3

The zero matrix:

| 0  0  0 |
| 0  0  0 |
| 0  0  0 |
Source

pub fn determinant(&self) -> f64

Returns the determinant of the matrix.

Computed as: [ \det(M) = a(ei - fh) - b(di - fg) + c(dh - eg) ]

§Examples
use lars::Mat3;
let m = Mat3::new(1.0, 2.0, 3.0, 3.0, 2.0, 1.0, 2.0, 1.0, 3.0);
assert_eq!(m.determinant(), -12.0);
Source

pub fn inverse(&self) -> Mat3

Returns the inverse of the matrix, if it exists.

Computed as: M⁻¹ = (1/det(M)) * adj(M) / 1 | ei - fh ch - bi bf - ce | M⁻¹ = —–– x | fg - di ai - cg cd - af | det(M) | dh - eg bg - ah ae - bd |

§Panics

Panics if the matrix is singular (determinant = 0).

§Examples
use lars::Mat3;
let m = Mat3::new(1.0, 2.0, 3.0, 3.0, 2.0, 1.0, 2.0, 1.0, 3.0);
assert_eq!(m.inverse(), Mat3::new(-5.0, 3.0, 4.0, 7.0, 3.0, -8.0, 1.0, -3.0, 4.0)/12.0);

Trait Implementations§

Source§

impl Add for Mat3

Source§

type Output = Mat3

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Mat3) -> Mat3

Performs the + operation. Read more
Source§

impl Clone for Mat3

Source§

fn clone(&self) -> Mat3

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 Debug for Mat3

Source§

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

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

impl<__RhsT: Copy> Div<__RhsT> for Mat3
where f64: Div<__RhsT, Output = f64>,

Source§

type Output = Mat3

The resulting type after applying the / operator.
Source§

fn div(self, rhs: __RhsT) -> Mat3

Performs the / operation. Read more
Source§

impl Mul<Mat3> for Vec3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat3) -> Vec3

Performs the * operation. Read more
Source§

impl Mul<Vec3> for Mat3

Source§

type Output = Vec3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec3) -> Vec3

Performs the * operation. Read more
Source§

impl Mul for Mat3

Source§

type Output = Mat3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat3) -> Mat3

Performs the * operation. Read more
Source§

impl PartialEq for Mat3

Source§

fn eq(&self, other: &Self) -> 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 PartialOrd for Mat3

Source§

fn partial_cmp(&self, other: &Mat3) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Mat3

Source§

type Output = Mat3

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Mat3) -> Mat3

Performs the - operation. Read more
Source§

impl Copy for Mat3

Auto Trait Implementations§

§

impl Freeze for Mat3

§

impl RefUnwindSafe for Mat3

§

impl Send for Mat3

§

impl Sync for Mat3

§

impl Unpin for Mat3

§

impl UnwindSafe for Mat3

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.