Struct mafs::Dmat4

source ·
#[repr(C)]
pub struct Dmat4 { /* private fields */ }
Expand description

4x4 matrix with double precision

It has the same layout as [Dvec4; 4], so it is aligned to 32 bytes.

Examples

use mafs::{Mat4, Dmat4, Vec4, Dvec4};

// Construction
let m1 = Dmat4::from_columns(
    Dvec4::new(1.0, 2.0, 3.0, 4.0),
    Dvec4::new(5.0, 6.0, 7.0, 8.0),
    Dvec4::new(9.0, 10.0, 11.0, 12.0),
    Dvec4::new(13.0, 14.0, 15.0, 16.0),
);
let m2 = Dmat4::from_columns(
    Dvec4::new(17.0, 18.0, 19.0, 20.0),
    Dvec4::new(21.0, 22.0, 23.0, 24.0),
    Dvec4::new(25.0, 26.0, 27.0, 28.0),
    Dvec4::new(29.0, 30.0, 31.0, 32.0),
);

// Matrix-Vector arithmetics
let v = Dvec4::new(17.0, 18.0, 19.0, 20.0);
assert_eq!(m1 * v, Dvec4::new(538.0, 612.0, 686.0, 760.0));

// Matrix-Matrix arithmetics
assert_eq!(m1 + m2, Dmat4::from_columns(
    Dvec4::new(18.0, 20.0, 22.0, 24.0),
    Dvec4::new(26.0, 28.0, 30.0, 32.0),
    Dvec4::new(34.0, 36.0, 38.0, 40.0),
    Dvec4::new(42.0, 44.0, 46.0, 48.0),
));
assert_eq!(m1 - m2, Dmat4::from_columns(
    Dvec4::new(-16.0, -16.0, -16.0, -16.0),
    Dvec4::new(-16.0, -16.0, -16.0, -16.0),
    Dvec4::new(-16.0, -16.0, -16.0, -16.0),
    Dvec4::new(-16.0, -16.0, -16.0, -16.0),
));
assert_eq!(m1 * m2, Dmat4::from_columns(
    Dvec4::new(538.0, 612.0, 686.0, 760.0),
    Dvec4::new(650.0, 740.0, 830.0, 920.0),
    Dvec4::new(762.0, 868.0, 974.0, 1080.0),
    Dvec4::new(874.0, 996.0, 1118.0, 1240.0),
));

// Transpose
assert_eq!(m1.transpose(), Dmat4::from_columns(
    Dvec4::new(1.0, 5.0, 9.0, 13.0),
    Dvec4::new(2.0, 6.0, 10.0, 14.0),
    Dvec4::new(3.0, 7.0, 11.0, 15.0),
    Dvec4::new(4.0, 8.0, 12.0, 16.0),
));

// Inverse of transformation matrices
let rotation_matrix = Dmat4::from_columns(
    Dvec4::new(1.0,          0.0,           0.0, 0.0),
    Dvec4::new(0.0, 1.0f64.cos(), -1.0f64.sin(), 0.0),
    Dvec4::new(0.0, 1.0f64.sin(),  1.0f64.cos(), 0.0),
    Dvec4::new(0.0,          0.0,           0.0, 1.0),
);
assert_eq!(rotation_matrix.inverse_se3(), rotation_matrix.transpose());
let rotation_and_translation = Dmat4::from_columns(
    Dvec4::new( 0.6666666666666666,  0.6666666666666666, -0.3333333333333333, 0.0),
    Dvec4::new(-0.3333333333333333,  0.6666666666666666,  0.6666666666666666, 0.0),
    Dvec4::new( 0.6666666666666666, -0.3333333333333333,  0.6666666666666666, 0.0),
    Dvec4::new(               -4.0,                 5.0,                 6.0, 1.0),
);
assert_eq!(rotation_and_translation.inverse_se3(), Dmat4::from_columns(
    Dvec4::new( 0.6666666666666666, -0.3333333333333333,  0.6666666666666666, 0.0),
    Dvec4::new( 0.6666666666666666,  0.6666666666666666, -0.3333333333333333, 0.0),
    Dvec4::new(-0.3333333333333333,  0.6666666666666666,  0.6666666666666666, 0.0),
    Dvec4::new( 1.3333333333333333,  -8.666666666666666, 0.33333333333333326, 1.0),
));

Trait Implementations§

source§

impl Add<Dmat4> for Dmat4

§

type Output = Dmat4

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AddAssign<Dmat4> for Dmat4

source§

fn add_assign(&mut self, rhs: Dmat4)

Performs the += operation. Read more
source§

impl Clone for Dmat4

source§

fn clone(&self) -> Dmat4

Returns a copy 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 Dmat4

source§

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

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

impl Default for Dmat4

source§

fn default() -> Dmat4

Returns the “default value” for a type. Read more
source§

impl Index<usize> for Dmat4

§

type Output = Dvec4

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &Dvec4

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Dmat4

source§

fn index_mut(&mut self, idx: usize) -> &mut Dvec4

Performs the mutable indexing (container[index]) operation. Read more
source§

impl Mat4<f64, Dvec4> for Dmat4

source§

fn from_columns(x: Dvec4, y: Dvec4, z: Dvec4, w: Dvec4) -> Dmat4

Create a new 4x4 matrix from its four columns.
source§

fn as_array(&self) -> &[Dvec4; 4]

Convert to an array. Can also use the indexing operator [].
source§

fn as_mut_array(&mut self) -> &mut [Dvec4; 4]

Convert to a mutable array. Can also use the indexing operator [].
source§

fn mul_vector(&self, rhs: Dvec4) -> Dvec4

Multiply this matrix with a vector. Can also use the * operator.
source§

fn transpose(&self) -> Dmat4

Transpose.
source§

fn splat(value: S) -> Self

Create a new 4x4 matrix with all equal components.
source§

fn from_rows(r0: [S; 4], r1: [S; 4], r2: [S; 4], r3: [S; 4]) -> Self

Create a new 4x4 matrix from its four rows
source§

fn identity() -> Self

Identity matrix.
source§

fn add_componentwise(&self, rhs: Self) -> Self

Add component by component. Can also use the + operator.
source§

fn sub_componentwise(&self, rhs: Self) -> Self

Subtract component by component. Can also use the - operator.
source§

fn mul_matrix(&self, rhs: Self) -> Self

Multiply this matrix with another matrix. Can also use the * operator.
source§

fn inverse_se3(&self) -> Self

Assume that this matrix is a rotation+translation matrix and computes its inverse. If this matrix is not a rotation+translation, the result will be nonsense.
source§

impl Mul<Dmat4> for Dmat4

§

type Output = Dmat4

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Dvec4> for Dmat4

§

type Output = Dvec4

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl MulAssign<Dmat4> for Dmat4

source§

fn mul_assign(&mut self, rhs: Dmat4)

Performs the *= operation. Read more
source§

impl Neg for Dmat4

§

type Output = Dmat4

The resulting type after applying the - operator.
source§

fn neg(self) -> Dmat4

Performs the unary - operation. Read more
source§

impl PartialEq<Dmat4> for Dmat4

source§

fn eq(&self, other: &Dmat4) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sub<Dmat4> for Dmat4

§

type Output = Dmat4

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl SubAssign<Dmat4> for Dmat4

source§

fn sub_assign(&mut self, rhs: Dmat4)

Performs the -= operation. Read more
source§

impl Copy for Dmat4

source§

impl StructuralPartialEq for Dmat4

Auto Trait Implementations§

§

impl RefUnwindSafe for Dmat4

§

impl Send for Dmat4

§

impl Sync for Dmat4

§

impl Unpin for Dmat4

§

impl UnwindSafe for Dmat4

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.