#[repr(C)]pub struct Matrix3<T: Scalar> {
pub col: [Vector3<T>; 3],
}Expand description
A 3x3 matrix stored in column-major order.
Commonly used for 2D transformations (with homogeneous coordinates) and 3D rotations.
§Layout
[m₀₀ m₀₁ m₀₂]
[m₁₀ m₁₁ m₁₂]
[m₂₀ m₂₁ m₂₂]Fields§
§col: [Vector3<T>; 3]Column vectors of the matrix
Implementations§
Source§impl<T: Scalar> Matrix3<T>
impl<T: Scalar> Matrix3<T>
Sourcepub fn new(
m0: T,
m1: T,
m2: T,
m3: T,
m4: T,
m5: T,
m6: T,
m7: T,
m8: T,
) -> Self
pub fn new( m0: T, m1: T, m2: T, m3: T, m4: T, m5: T, m6: T, m7: T, m8: T, ) -> Self
Creates a new 3x3 matrix from column-major elements.
Sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Computes the determinant of the matrix.
Sourcepub fn inverse(&self) -> Self
pub fn inverse(&self) -> Self
Computes the inverse of the matrix.
Uses the adjugate matrix method:
M⁻¹ = (1/det(M)) * adj(M)§Note
Returns NaN or Inf if the matrix is singular (determinant = 0).
Sourcepub fn mul_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn mul_matrix_matrix(l: &Self, r: &Self) -> Self
Multiplies two 3x3 matrices.
Matrix multiplication follows the rule:
C[i,j] = Σₖ A[i,k] * B[k,j]Sourcepub fn mul_matrix_vector(l: &Self, r: &Vector3<T>) -> Vector3<T>
pub fn mul_matrix_vector(l: &Self, r: &Vector3<T>) -> Vector3<T>
Multiplies a 3x3 matrix by a 3D vector.
Transforms the vector by the matrix:
v' = M * vSourcepub fn mul_vector_matrix(l: &Vector3<T>, r: &Self) -> Vector3<T>
pub fn mul_vector_matrix(l: &Vector3<T>, r: &Self) -> Vector3<T>
Multiplies a 3D vector by a 3x3 matrix (row vector).
v' = vᵀ * MSourcepub fn add_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn add_matrix_matrix(l: &Self, r: &Self) -> Self
Adds two matrices element-wise.
C[i,j] = A[i,j] + B[i,j]Sourcepub fn sub_matrix_matrix(l: &Self, r: &Self) -> Self
pub fn sub_matrix_matrix(l: &Self, r: &Self) -> Self
Subtracts two matrices element-wise.
C[i,j] = A[i,j] - B[i,j]Source§impl<T: FloatScalar> Matrix3<T>
impl<T: FloatScalar> Matrix3<T>
Sourcepub fn of_axis_angle(axis: &Vector3<T>, angle: T, epsilon: T) -> Option<Self>
pub fn of_axis_angle(axis: &Vector3<T>, angle: T, epsilon: T) -> Option<Self>
Creates a 3x3 rotation matrix from an axis and angle.
Uses Rodrigues’ rotation formula:
R = I + sin(θ)K + (1 - cos(θ))K²where K is the cross-product matrix of the normalized axis.
§Parameters
axis: The rotation axis (will be normalized)angle: The rotation angle in radiansepsilon: Minimum axis length to treat as valid
§Returns
Some(matrix)for a valid axisNoneif the axis length is too small