#[repr(transparent)]pub struct Matrix<Repr, Map>(pub Repr, _);Expand description
A generic matrix type.
Tuple Fields§
§0: ReprImplementations§
Source§impl<Sc, const N: usize, const M: usize, Map> Matrix<[[Sc; N]; M], Map>
impl<Sc, const N: usize, const M: usize, Map> Matrix<[[Sc; N]; M], Map>
Source§impl<Sc: Copy, const N: usize, const DIM: usize, S, D> Matrix<[[Sc; N]; N], RealToReal<DIM, S, D>>
impl<Sc: Copy, const N: usize, const DIM: usize, S, D> Matrix<[[Sc; N]; N], RealToReal<DIM, S, D>>
Source§impl<M: LinearMap> Matrix<[[f32; 4]; 4], M>
impl<M: LinearMap> Matrix<[[f32; 4]; 4], M>
Sourcepub const fn from_basis(i: Vec3, j: Vec3, k: Vec3) -> Self
pub const fn from_basis(i: Vec3, j: Vec3, k: Vec3) -> Self
Constructs a matrix from a set of basis vectors.
Source§impl<Sc, const N: usize, Map> Matrix<[[Sc; N]; N], Map>
impl<Sc, const N: usize, Map> Matrix<[[Sc; N]; N], Map>
Sourcepub fn compose<Inner: LinearMap>(
&self,
other: &Matrix<[[Sc; N]; N], Inner>,
) -> Matrix<[[Sc; N]; N], <Map as Compose<Inner>>::Result>where
Map: Compose<Inner>,
pub fn compose<Inner: LinearMap>(
&self,
other: &Matrix<[[Sc; N]; N], Inner>,
) -> Matrix<[[Sc; N]; N], <Map as Compose<Inner>>::Result>where
Map: Compose<Inner>,
Returns the composite transform of self and other.
Computes the matrix product of self and other such that applying
the resulting transformation is equivalent to first applying other
and then self. More succinctly,
(𝗠 ∘ 𝗡)𝘃 = 𝗠(𝗡𝘃)for some matrices 𝗠 and 𝗡 and a vector 𝘃.
Sourcepub fn then<Outer: Compose<Map>>(
&self,
other: &Matrix<[[Sc; N]; N], Outer>,
) -> Matrix<[[Sc; N]; N], <Outer as Compose<Map>>::Result>
pub fn then<Outer: Compose<Map>>( &self, other: &Matrix<[[Sc; N]; N], Outer>, ) -> Matrix<[[Sc; N]; N], <Outer as Compose<Map>>::Result>
Returns the composite transform of other and self.
Computes the matrix product of self and other such that applying
the resulting matrix is equivalent to first applying self and then
other. The call self.then(other) is thus equivalent to
other.compose(self).
Source§impl<Src, Dst> Matrix<[[f32; 3]; 3], RealToReal<2, Src, Dst>>
impl<Src, Dst> Matrix<[[f32; 3]; 3], RealToReal<2, Src, Dst>>
Sourcepub fn apply(&self, v: &Vec2<Src>) -> Vec2<Dst>
pub fn apply(&self, v: &Vec2<Src>) -> Vec2<Dst>
Maps the real 2-vector 𝘃 from basis Src to basis Dst.
Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃2 component with value 1:
/ M00 · · \ / v0 \
Mv = | · · · | | v1 | = ( v0' v1' 1 )
\ · · M22 / \ 1 /Source§impl<Src, Dst> Matrix<[[f32; 4]; 4], RealToReal<3, Src, Dst>>
impl<Src, Dst> Matrix<[[f32; 4]; 4], RealToReal<3, Src, Dst>>
Sourcepub fn apply(&self, v: &Vec3<Src>) -> Vec3<Dst>
pub fn apply(&self, v: &Vec3<Src>) -> Vec3<Dst>
Maps the real 3-vector 𝘃 from basis Src to basis Dst.
Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃3 component with value 1:
/ M00 · · · \ / v0 \
Mv = | · · · · | | v1 | = ( v0' v1' v2' 1 )
| · · · · | | v2 |
\ · · · M33 / \ 1 /Sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Returns the determinant of self.
Given a matrix M,
/ a b c d \
M = | e f g h |
| i j k l |
\ m n o p /its determinant can be computed by recursively computing the determinants of sub-matrices on rows 1.. and multiplying them by the elements on row 0:
| f g h | | e g h |
det(M) = a · | j k l | - b · | i k l | + - ···
| n o p | | m o p |Sourcepub fn inverse(&self) -> Mat4x4<RealToReal<3, Dst, Src>>
pub fn inverse(&self) -> Mat4x4<RealToReal<3, Dst, Src>>
Returns the inverse matrix of self.
The inverse 𝝡-1 of matrix 𝝡 is a matrix that, when composed with 𝝡, results in the identity matrix:
𝝡 ∘ 𝝡-1 = 𝝡-1 ∘ 𝝡 = 𝐈
In other words, it applies the transform of 𝝡 in reverse. Given vectors 𝘃 and 𝘂,
𝝡𝘃 = 𝘂 ⇔ 𝝡-1 𝘂 = 𝘃.
Only matrices with a nonzero determinant have a defined inverse. A matrix without an inverse is said to be singular.
Note: This method uses naive Gauss–Jordan elimination and may suffer from imprecision or numerical instability in certain cases.
§Panics
If self is singular or near-singular:
- Panics in debug mode.
- Does not panic in release mode, but the result may be inaccurate
or contain
Infs orNaNs.
Source§impl<Src> Matrix<[[f32; 4]; 4], RealToProj<Src>>
impl<Src> Matrix<[[f32; 4]; 4], RealToProj<Src>>
Sourcepub fn apply(&self, v: &Vec3<Src>) -> ProjVec4
pub fn apply(&self, v: &Vec3<Src>) -> ProjVec4
Maps the real 3-vector 𝘃 from basis 𝖡 to the projective 4-space.
Computes the matrix–vector multiplication 𝝡𝘃 where 𝘃 is interpreted as a column vector with an implicit 𝘃3 component with value 1:
/ M00 · · \ / v0 \
Mv = | · | | v1 | = ( v0' v1' v2' v3' )
| · | | v2 |
\ · · M33 / \ 1 /