#[repr(C)]pub struct Matrix3<U: Scalar> {
pub x_axis: Vector3<U>,
pub y_axis: Vector3<U>,
pub z_axis: Vector3<U>,
}
Expand description
Fields§
§x_axis: Vector3<U>
§y_axis: Vector3<U>
§z_axis: Vector3<U>
Implementations§
source§impl<T> Matrix3<T>where
T: FloatScalar,
impl<T> Matrix3<T>where
T: FloatScalar,
sourcepub const IDENTITY: Self = _
pub const IDENTITY: Self = _
Identity matrix
§Example
let matrix = Matrix3::<f32>::IDENTITY;
assert_eq!(matrix.row(0), vec3!(1.0, 0.0, 0.0));
assert_eq!(matrix.row(1), vec3!(0.0, 1.0, 0.0));
assert_eq!(matrix.row(2), vec3!(0.0, 0.0, 1.0));
sourcepub fn transform_point<U: Unit<Scalar = T>>(
&self,
point: Point2<U>,
) -> Point2<U>
pub fn transform_point<U: Unit<Scalar = T>>( &self, point: Point2<U>, ) -> Point2<U>
Transform 2D point.
See glam::Mat3::transform_point2()
or
glam::DMat3::transform_point2()
(depending on the scalar).
§Example
let matrix = Matrix3::<f32>::from_angle(Angle::<f32>::from_degrees(90.0));
let point = Point2::<f32> { x: 1.0, y: 0.0 };
let rotated = matrix.transform_point(point);
approx::assert_abs_diff_eq!(rotated, point!(0.0, 1.0));
sourcepub fn transform_vector<U: Unit<Scalar = T>>(
&self,
vector: Vector2<U>,
) -> Vector2<U>
pub fn transform_vector<U: Unit<Scalar = T>>( &self, vector: Vector2<U>, ) -> Vector2<U>
Transform 2D vector.
See glam::Mat3::transform_vector2()
or
glam::DMat3::transform_vector2()
(depending on the scalar).
source§impl<T: FloatScalar> Matrix3<T>
impl<T: FloatScalar> Matrix3<T>
sourcepub fn determinant(&self) -> T::Scalar
pub fn determinant(&self) -> T::Scalar
Returns the determinant of self
.
sourcepub fn mul_scalar(&self, rhs: T::Scalar) -> Self
pub fn mul_scalar(&self, rhs: T::Scalar) -> Self
Multiplies the matrix by a scalar.
sourcepub fn div_scalar(&self, rhs: T::Scalar) -> Self
pub fn div_scalar(&self, rhs: T::Scalar) -> Self
Divides the matrix by a scalar.
sourcepub fn from_cols(
x_axis: Vector3<T>,
y_axis: Vector3<T>,
z_axis: Vector3<T>,
) -> Self
pub fn from_cols( x_axis: Vector3<T>, y_axis: Vector3<T>, z_axis: Vector3<T>, ) -> Self
Creates a 3x3 matrix from three column vectors.
sourcepub fn transform_vector2(&self, vector: Vector2<T>) -> Vector2<T>
pub fn transform_vector2(&self, vector: Vector2<T>) -> Vector2<T>
Rotates the given 2D vector.
This is the equivalent of multiplying rhs
as a 3D vector where z
is 0
.
This method assumes that self
contains a valid affine transform.
§Panics
Will panic if the 2nd row of self
is not (0, 0, 1)
when glam_assert
is enabled.
sourcepub fn transform_point2(&self, point: Point2<T>) -> Point2<T>
pub fn transform_point2(&self, point: Point2<T>) -> Point2<T>
Transforms the given 2D point.
This is the equivalent of multiplying rhs
as a 3D vector where z
is 1
.
This method assumes that self
contains a valid affine transform.
§Panics
Will panic if the 2nd row of self
is not (0, 0, 1)
when glam_assert
is enabled.
sourcepub fn from_scale(vector: Vector2<T>) -> Self
pub fn from_scale(vector: Vector2<T>) -> Self
Creates an affine transformation matrix from the given non-uniform 2D scale
.
See (e.g.) glam::Mat3::from_scale()
.
sourcepub fn from_angle(angle: Angle<T::Scalar>) -> Self
pub fn from_angle(angle: Angle<T::Scalar>) -> Self
Creates an affine transformation matrix from the given 2D rotation angle
.
See (e.g.) glam::Mat3::from_angle()
.
sourcepub fn from_axis_angle(axis: Vector3<T>, angle: Angle<T::Scalar>) -> Self
pub fn from_axis_angle(axis: Vector3<T>, angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from a normalized rotation axis
and angle
.
sourcepub fn from_translation(translation: Vector2<T>) -> Self
pub fn from_translation(translation: Vector2<T>) -> Self
Creates an affine transformation matrix from the given 2D translation
.
See (e.g.) glam::Mat3::from_translation()
.
sourcepub fn from_scale_angle_translation(
scale: Vector2<T>,
angle: Angle<T::Scalar>,
translation: Vector2<T>,
) -> Self
pub fn from_scale_angle_translation( scale: Vector2<T>, angle: Angle<T::Scalar>, translation: Vector2<T>, ) -> Self
Creates an affine transformation matrix from the given 2D scale
, rotation angle
and translation
.
See (e.g.) glam::Mat3::from_scale_angle_translation()
.
sourcepub fn from_diagonal(diagonal: Vector3<T>) -> Self
pub fn from_diagonal(diagonal: Vector3<T>) -> Self
Creates a 3x3 matrix with its diagonal set to diagonal
and all other entries set to 0.
sourcepub fn from_quat(rotation: <T::Scalar as FloatScalar>::Quat) -> Self
pub fn from_quat(rotation: <T::Scalar as FloatScalar>::Quat) -> Self
Creates a 3D rotation matrix from the given quaternion.
sourcepub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_x(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle
around the x axis.
sourcepub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_y(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle
around the y axis.
sourcepub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self
pub fn from_rotation_z(angle: Angle<T::Scalar>) -> Self
Creates a 3D rotation matrix from angle
around the z axis.
sourcepub fn from_mat2(mat2: Matrix2<T::Scalar>) -> Self
pub fn from_mat2(mat2: Matrix2<T::Scalar>) -> Self
Creates an affine transformation matrix from the given 2x2 matrix.
sourcepub fn from_mat4(mat4: Matrix4<T::Scalar>) -> Self
pub fn from_mat4(mat4: Matrix4<T::Scalar>) -> Self
Creates a 3x3 matrix from a 4x4 matrix, discarding the 4th row and column.
sourcepub fn from_mat4_minor(mat4: Matrix4<T::Scalar>, i: usize, j: usize) -> Self
pub fn from_mat4_minor(mat4: Matrix4<T::Scalar>, i: usize, j: usize) -> Self
Creates a 3x3 matrix from the minor of the given 4x4 matrix, discarding the i
th column and j
th row.
§Panics
Panics if i`` or
j` is greater than 3.
sourcepub fn to_cols_array(&self) -> [T::Scalar; 9]
pub fn to_cols_array(&self) -> [T::Scalar; 9]
Creates a [T; 9]
array storing data in column major order.
sourcepub fn to_cols_array_2d(&self) -> [[T::Scalar; 3]; 3]
pub fn to_cols_array_2d(&self) -> [[T::Scalar; 3]; 3]
Creates a [[T; 3]; 3]
2D array storing data in column major order.
sourcepub fn from_cols_array(array: &[T::Scalar; 9]) -> Self
pub fn from_cols_array(array: &[T::Scalar; 9]) -> Self
Creates a 3x3 matrix from a [T; 9]
array stored in column major order.
sourcepub fn from_rows(r0: Vector3<T>, r1: Vector3<T>, r2: Vector3<T>) -> Self
pub fn from_rows(r0: Vector3<T>, r1: Vector3<T>, r2: Vector3<T>) -> Self
Create from rows (i.e., transposed).
sourcepub fn is_invertible(&self) -> bool
pub fn is_invertible(&self) -> bool
Return true if the determinant is finite and nonzero.
sourcepub fn try_inverse(&self) -> Option<Self>
pub fn try_inverse(&self) -> Option<Self>
Get the inverse if the matrix is invertible.
sourcepub fn to_rows_array(&self) -> [T; 9]
pub fn to_rows_array(&self) -> [T; 9]
Get the columns of the transposed matrix as a scalar array.
sourcepub fn to_rows_array_2d(&self) -> [[T; 3]; 3]
pub fn to_rows_array_2d(&self) -> [[T; 3]; 3]
Get the columns of the transposed matrix.
Trait Implementations§
source§impl<T> AbsDiffEq for Matrix3<T>
impl<T> AbsDiffEq for Matrix3<T>
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
source§fn abs_diff_ne(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Self, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<T> Debug for Matrix3<T>where
T: FloatScalar,
impl<T> Debug for Matrix3<T>where
T: FloatScalar,
source§impl<T> Default for Matrix3<T>where
T: FloatScalar,
impl<T> Default for Matrix3<T>where
T: FloatScalar,
source§impl<T> Div<T> for Matrix3<T>where
T: FloatScalar,
impl<T> Div<T> for Matrix3<T>where
T: FloatScalar,
source§impl<T> DivAssign<T> for Matrix3<T>where
T: FloatScalar,
impl<T> DivAssign<T> for Matrix3<T>where
T: FloatScalar,
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresource§impl<T> Mul<T> for Matrix3<T>where
T: FloatScalar,
impl<T> Mul<T> for Matrix3<T>where
T: FloatScalar,
source§impl<T> Mul for Matrix3<T>where
T: FloatScalar,
impl<T> Mul for Matrix3<T>where
T: FloatScalar,
source§impl<T> MulAssign<T> for Matrix3<T>where
T: FloatScalar,
impl<T> MulAssign<T> for Matrix3<T>where
T: FloatScalar,
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresource§impl<T> RelativeEq for Matrix3<T>
impl<T> RelativeEq for Matrix3<T>
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
source§fn relative_ne(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq
.source§impl<T: FloatScalar> Transparent for Matrix3<T>
impl<T: FloatScalar> Transparent for Matrix3<T>
source§type Wrapped = <T as FloatScalar>::Mat3
type Wrapped = <T as FloatScalar>::Mat3
Self
.source§impl<T: FloatScalar> UlpsEq for Matrix3<T>
impl<T: FloatScalar> UlpsEq for Matrix3<T>
impl<U: Copy + Scalar> Copy for Matrix3<U>
impl<U: Eq + Scalar> Eq for Matrix3<U>
impl<T: Scalar> Pod for Matrix3<T>
impl<U: Scalar> StructuralPartialEq for Matrix3<U>
Auto Trait Implementations§
impl<U> Freeze for Matrix3<U>where
U: Freeze,
impl<U> RefUnwindSafe for Matrix3<U>where
U: RefUnwindSafe,
impl<U> Send for Matrix3<U>
impl<U> Sync for Matrix3<U>
impl<U> Unpin for Matrix3<U>where
U: Unpin,
impl<U> UnwindSafe for Matrix3<U>where
U: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
source§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)