pub struct Mat3<T>(pub Vec3<T>, pub Vec3<T>, pub Vec3<T>);Tuple Fields§
§0: Vec3<T>§1: Vec3<T>§2: Vec3<T>Implementations§
Source§impl<T> Mat3<T>
impl<T> Mat3<T>
Sourcepub fn new(col0: &Vec3<T>, col1: &Vec3<T>, col2: &Vec3<T>) -> Self
pub fn new(col0: &Vec3<T>, col1: &Vec3<T>, col2: &Vec3<T>) -> Self
Creates a new 3x3 matrix from three columns.
This constructor initializes a Mat3 instance with the provided column vectors.
Each column vector is represented as a Vec3<T>.
§Parameters
col0: The first column of the matrix.col1: The second column of the matrix.col2: The third column of the matrix.
§Returns
Returns a Mat3 instance with the specified columns.
§Examples
let col0 = Vec3::new(1.0, 0.0, 0.0);
let col1 = Vec3::new(0.0, 1.0, 0.0);
let col2 = Vec3::new(0.0, 0.0, 1.0);
let matrix = Mat3::new(&col0, &col1, &col2);Sourcepub fn identity() -> Self
pub fn identity() -> Self
Creates an identity matrix.
This constructor initializes a Mat3 instance as the identity matrix, which has 1s on the diagonal
and 0s elsewhere. This is useful for matrix transformations where the identity matrix represents no change.
§Returns
Returns a Mat3 instance representing the identity matrix.
§Examples
let matrix = Mat3::identity();Sourcepub fn determinant(&self) -> T
pub fn determinant(&self) -> T
Calculates the determinant of the matrix.
This function computes the determinant of the 3x3 matrix, which can be used to determine if the matrix is invertible (a non-zero determinant indicates the matrix is invertible).
§Returns
Returns the determinant of the matrix.
§Examples
let matrix = Mat3::identity();
let det = matrix.determinant();
assert_eq!(det, 1.0); // Determinant of the identity matrixSourcepub fn trace(&self) -> T
pub fn trace(&self) -> T
Computes the trace of the matrix.
The trace of a matrix is the sum of its diagonal elements. For a 3x3 matrix, it is the sum of self.0.x,
self.1.y, and self.2.z.
§Returns
Returns the trace of the matrix.
§Examples
let matrix = Mat3::identity();
let trace = matrix.trace();
assert_eq!(trace, 3.0); // Trace of the identity matrixSourcepub fn mul(&self, other: &Self) -> Self
pub fn mul(&self, other: &Self) -> Self
Multiplies the current matrix by another matrix.
This function performs matrix multiplication with another Mat3 instance. The resulting matrix is computed
as the dot products of rows from the first matrix and columns from the second matrix.
§Parameters
other: The matrix to multiply with.
§Returns
Returns the product of the two matrices.
§Examples
let a = Mat3::identity();
let b = Mat3::identity();
let product = a.mul(&b);
assert_eq!(product, a); // Product of two identity matrices is an identity matrixSourcepub fn translate_2d(&mut self, translate: &Vec2<T>)
pub fn translate_2d(&mut self, translate: &Vec2<T>)
Translates the matrix in 2D space.
This function translates the matrix by adding the translation vector to the matrix’s translation components.
§Parameters
translate: The 2D translation vector.
§Examples
let mut matrix = Mat3::identity();
let translate = Vec2::new(2.0, 3.0);
matrix.translate_2d(&translate);Sourcepub fn scale_3d(&mut self, scale: &Vec3<T>)
pub fn scale_3d(&mut self, scale: &Vec3<T>)
Scales the matrix in 3D space.
This function scales the matrix by multiplying each component of the matrix with the corresponding component of the scale vector.
§Parameters
scale: The 3D scale vector.
§Examples
let mut matrix = Mat3::identity();
let scale = Vec3::new(2.0, 3.0, 4.0);
matrix.scale_3d(&scale);Source§impl<T> Mat3<T>
impl<T> Mat3<T>
Sourcepub fn invert(&self) -> Option<Self>
pub fn invert(&self) -> Option<Self>
Computes the inverse of the matrix.
This method calculates the inverse of the 3x3 matrix, if it exists. The inverse of a matrix is used to
reverse the effects of the matrix transformation. If the matrix is singular (i.e., its determinant is zero),
the function returns None.
§Returns
Returns Some(Self) containing the inverse of the matrix if the determinant is non-zero; otherwise, returns None.
§Examples
let matrix = Mat3::identity();
let inverse = matrix.invert();
assert!(inverse.is_some()); // Identity matrix is invertibleSourcepub fn rotate_2d(&mut self, angle: T)
pub fn rotate_2d(&mut self, angle: T)
Rotates the matrix by a given angle in 2D space.
This method applies a 2D rotation transformation to the matrix. The rotation is counterclockwise by the specified angle in radians. This transformation affects only the 2D components of the matrix.
§Parameters
angle: The angle of rotation in radians.
§Examples
let mut matrix = Mat3::identity();
matrix.rotate_2d(std::f64::consts::FRAC_PI_2); // Rotate by 90 degreesSourcepub fn rotate_3d(&mut self, axis: Vec3<T>, angle: T)
pub fn rotate_3d(&mut self, axis: Vec3<T>, angle: T)
Rotates the matrix by a given angle around a specified 3D axis.
This method applies a 3D rotation transformation to the matrix. The rotation is counterclockwise around the specified axis by the given angle in radians. The axis is normalized before applying the rotation.
§Parameters
axis: The 3D axis around which to rotate.angle: The angle of rotation in radians.
§Examples
let mut matrix = Mat3::identity();
let axis = Vec3::new(0.0, 0.0, 1.0); // Rotation around the Z axis
matrix.rotate_3d(axis, std::f64::consts::FRAC_PI_2); // Rotate by 90 degreesSourcepub fn rotate_x_3d(&mut self, angle: T)
pub fn rotate_x_3d(&mut self, angle: T)
Rotates the matrix by a given angle around the X-axis in 3D space.
This method applies a 3D rotation transformation to the matrix around the X-axis. The rotation is counterclockwise by the specified angle in radians.
§Parameters
angle: The angle of rotation in radians.
§Examples
let mut matrix = Mat3::identity();
matrix.rotate_x_3d(std::f64::consts::FRAC_PI_2); // Rotate around X-axis by 90 degreesSourcepub fn rotate_y_3d(&mut self, angle: T)
pub fn rotate_y_3d(&mut self, angle: T)
Rotates the matrix by a given angle around the Y-axis in 3D space.
This method applies a 3D rotation transformation to the matrix around the Y-axis. The rotation is counterclockwise by the specified angle in radians.
§Parameters
angle: The angle of rotation in radians.
§Examples
let mut matrix = Mat3::identity();
matrix.rotate_y_3d(std::f64::consts::FRAC_PI_2); // Rotate around Y-axis by 90 degreesSourcepub fn rotate_z_3d(&mut self, angle: T)
pub fn rotate_z_3d(&mut self, angle: T)
Rotates the matrix by a given angle around the Z-axis in 3D space.
This method applies a 3D rotation transformation to the matrix around the Z-axis. The rotation is counterclockwise by the specified angle in radians.
§Parameters
angle: The angle of rotation in radians.
§Examples
let mut matrix = Mat3::identity();
matrix.rotate_z_3d(std::f64::consts::FRAC_PI_2); // Rotate around Z-axis by 90 degrees