Skip to main content

Mat3

Struct Mat3 

Source
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>
where T: NumAssign + Copy,

Source

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);
Source

pub fn zero() -> Self

Creates a 3x3 zero matrix.

This constructor initializes a Mat3 instance where all elements are set to zero.

§Returns

Returns a Mat3 instance where all columns are zero vectors.

§Examples
let matrix = Mat3::zero();
Source

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();
Source

pub fn transpose(&self) -> Self

Computes the transpose of the matrix.

This function returns a new Mat3 instance where the rows and columns of the original matrix are swapped.

§Returns

Returns the transpose of the matrix.

§Examples
let matrix = Mat3::identity();
let transposed = matrix.transpose();
Source

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 matrix
Source

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 matrix
Source

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 matrix
Source

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);
Source

pub fn scale_2d(&mut self, scale: &Vec2<T>)

Scales the matrix in 2D space.

This function scales the matrix by multiplying the appropriate components of the matrix by the given scale vector.

§Parameters
  • scale: The 2D scale vector.
§Examples
let mut matrix = Mat3::identity();
let scale = Vec2::new(2.0, 3.0);
matrix.scale_2d(&scale);
Source

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>
where T: NumAssign + Float,

Source

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 invertible
Source

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 degrees
Source

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 degrees
Source

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 degrees
Source

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 degrees
Source

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

Trait Implementations§

Source§

impl<T> Add for Mat3<T>
where T: NumAssign + Copy,

Source§

type Output = Mat3<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Mat3<T>

Source§

fn clone(&self) -> Mat3<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Mat3<T>

Source§

impl<T: Debug> Debug for Mat3<T>

Source§

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

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

impl<T: Default> Default for Mat3<T>

Source§

fn default() -> Mat3<T>

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

impl<T> Display for Mat3<T>
where T: Display,

Source§

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

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

impl<T> Div<T> for Mat3<T>
where T: NumAssign + Copy,

Source§

type Output = Mat3<T>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: T) -> Self

Performs the / operation. Read more
Source§

impl<T> Index<usize> for Mat3<T>

Source§

type Output = Vec3<T>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<T> IndexMut<usize> for Mat3<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

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

impl<'a, T> IntoIterator for &'a Mat3<T>
where T: NumAssign + Copy,

Source§

type Item = &'a Vec3<T>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Vec3<T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Mat3<T>
where T: NumAssign + Copy,

Source§

type Item = &'a mut Vec3<T>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Vec3<T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> Mul for Mat3<T>
where T: NumAssign + Copy,

Source§

type Output = Mat3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Mat3<T>) -> Mat3<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Mat3<T>
where T: NumAssign + Copy,

Source§

type Output = Mat3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: T) -> Self

Performs the * operation. Read more
Source§

impl<T> Neg for Mat3<T>
where T: NumAssign + Copy + Neg<Output = T>,

Source§

type Output = Mat3<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: PartialEq> PartialEq for Mat3<T>

Source§

fn eq(&self, other: &Mat3<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T> StructuralPartialEq for Mat3<T>

Source§

impl<T> Sub for Mat3<T>
where T: NumAssign + Copy,

Source§

type Output = Mat3<T>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Mat3<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Mat3<T>
where T: RefUnwindSafe,

§

impl<T> Send for Mat3<T>
where T: Send,

§

impl<T> Sync for Mat3<T>
where T: Sync,

§

impl<T> Unpin for Mat3<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Mat3<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Mat3<T>
where T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.