spatial::Mat3
On this page
28approx_eqcoldeterminantfrom_axis_anglefrom_colsfrom_cols_arrayfrom_diagonalfrom_eulerfrom_mat2from_mat4from_quatfrom_rotation_xfrom_rotation_yfrom_rotation_zfrom_scale_angle_translationfrom_translationidentityinverseis_finiterowto_cols_arrayto_eulertransform_point2transform_vectortransform_vector2transposetry_inversezero
Mat3Source
pub struct Mat3<T = f32>A 3x3 matrix of three column vectors: a rotation and scale in 3D, or
a 2D transform in homogeneous coordinates (transform_point2).
Mat3 alone is Mat3<f32>. #[repr(C)]: x_axis, y_axis,
z_axis, nine Ts column by column. A WGSL mat3x3<f32> pads each
column to 16 bytes: upload Mat4::from_mat3(m) or three Vec3As.
use spatial::{Mat3, Vec3};
let m = Mat3::from_rotation_z(f32::PI / 2.0);
assert((m * Vec3::X).approx_eq(Vec3::Y, 1e-6));
The matrix of its columns.
nabiuse spatial::{Mat3, Vec3}; assert(Mat3::from_cols(Vec3::X, Vec3::Y, Vec3::Z) == Mat3::IDENTITY);From nine values, column by column.
nabilet m = spatial::DMat3::from_cols_array([1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]); assert(m == spatial::DMat3::IDENTITY);The nine values column by column.
nabiassert(spatial::Mat3::IDENTITY.to_cols_array()[4] == 1.0);The identity.
nabiassert(spatial::Mat3::<f32>::identity() == spatial::Mat3::IDENTITY);All zero.
nabiassert(spatial::Mat3::<f32>::zero().determinant() == 0.0);The diagonal matrix of
d, a 3D scale.nabiuse spatial::{Mat3, Vec3}; assert(Mat3::from_diagonal(Vec3::new(1.0, 2.0, 3.0)) * Vec3::ONE == Vec3::new(1.0, 2.0, 3.0));The rotation of a unit quaternion.
nabiuse spatial::{Mat3, Quat, Vec3}; let q = Quat::from_rotation_y(0.5); assert((Mat3::from_quat(q) * Vec3::X).approx_eq(q * Vec3::X, 1e-6));The rotation by
angleradians about the unit vectoraxis.nabiuse spatial::{Mat3, Vec3}; assert((Mat3::from_axis_angle(Vec3::X, f32::PI / 2.0) * Vec3::Y).approx_eq(Vec3::Z, 1e-6));The rotation by
angleradians about +x.nabiuse spatial::{Mat3, Vec3}; assert((Mat3::from_rotation_x(f32::PI / 2.0) * Vec3::Y).approx_eq(Vec3::Z, 1e-6));The rotation by
angleradians about +y.nabiuse spatial::{Mat3, Vec3}; assert((Mat3::from_rotation_y(f32::PI / 2.0) * Vec3::Z).approx_eq(Vec3::X, 1e-6));The rotation by
angleradians about +z.nabiuse spatial::{Mat3, Vec3}; assert((Mat3::from_rotation_z(f32::PI / 2.0) * Vec3::X).approx_eq(Vec3::Y, 1e-6));
Sourcepub fn from_euler(§order: EulerOrder, a: T, b: T, c: T) -> Mat3<T> The rotation of Euler angles in radians: see
EulerOrder.nabiuse spatial::{EulerOrder, Mat3}; let m = Mat3::from_euler(EulerOrder::ZYX, 0.0, 0.0, 0.5); assert(m.approx_eq(Mat3::from_rotation_x(0.5), 1e-6));
Sourcepub fn to_euler(§self, order: EulerOrder) -> (T, T, T) The Euler angles of a rotation matrix: see
Quat::to_euler.nabiuse spatial::{EulerOrder, Mat3}; let (a, b, c) = Mat3::<f64>::from_rotation_y(0.25).to_euler(EulerOrder::YXZ); assert((a - 0.25).abs() < 1e-12 && b.abs() < 1e-12 && c.abs() < 1e-12);The upper-left 3x3 of
m: its rotation and scale.nabiuse spatial::{Mat3, Mat4, Vec3}; assert(Mat3::from_mat4(Mat4::from_translation(Vec3::ONE)) == Mat3::IDENTITY);mas the upper-left 2x2, 1 in the corner: a 2D linear map in homogeneous coordinates.nabiuse spatial::{Mat2, Mat3}; assert(Mat3::from_mat2(Mat2::IDENTITY) == Mat3::IDENTITY);The 2D translation by
t, in homogeneous coordinates.nabiuse spatial::{Mat3, Vec2}; assert(Mat3::from_translation(Vec2::new(1.0, 2.0)).transform_point2(Vec2::ZERO) == Vec2::new(1.0, 2.0));The 2D transform that scales by
scale, rotates byangleradians, then moves byt.nabiuse spatial::{Mat3, Vec2}; let m = Mat3::from_scale_angle_translation(Vec2::splat(2.0), f32::PI / 2.0, Vec2::new(1.0, 0.0)); assert(m.transform_point2(Vec2::X).approx_eq(Vec2::new(1.0, 2.0), 1e-6));The 2D point
ptransformed, translation included (z = 1, no perspective divide).nabiuse spatial::{Mat3, Vec2}; assert(Mat3::from_translation(Vec2::X).transform_point2(Vec2::Y) == Vec2::ONE);The 2D direction
vtransformed, translation left out (z = 0).nabiuse spatial::{Mat3, Vec2}; assert(Mat3::from_translation(Vec2::X).transform_vector2(Vec2::Y) == Vec2::Y);Column
i(0, 1 or 2).nabiassert(spatial::Mat3::IDENTITY.col(2) == spatial::Vec3::Z);Row
i(0, 1 or 2).nabiassert(spatial::Mat3::IDENTITY.row(0) == spatial::Vec3::X);The transpose; the inverse of a rotation.
nabiuse spatial::DMat3; let r = DMat3::from_rotation_x(0.3); assert((r * r.transpose()).approx_eq(DMat3::IDENTITY, 1e-12));The determinant,
x_axis . (y_axis x z_axis).nabiuse spatial::{Mat3, Vec3}; assert(Mat3::from_diagonal(Vec3::new(1.0, 2.0, 3.0)).determinant() == 6.0);The inverse. A singular matrix gives infinite or NaN entries;
try_inversegivesnonefor it instead.nabiuse spatial::{DMat3, DVec3}; let m = DMat3::from_cols(DVec3::new(2.0, 0.0, 1.0), DVec3::new(0.0, 1.0, 0.0), DVec3::new(1.0, 0.0, 3.0)); assert((m.inverse() * m).approx_eq(DMat3::IDENTITY, 1e-12));The inverse, or
nonewhen the determinant is zero or the result is not finite.nabiassert(spatial::Mat3::<f32>::zero().try_inverse() == none);The vector
vtransformed, the same asself * v.nabiuse spatial::{Mat3, Vec3}; assert(Mat3::IDENTITY.transform_vector(Vec3::ONE) == Vec3::ONE);Whether every entry is within
epsofo's.nabiuse spatial::Mat3; assert(Mat3::IDENTITY.approx_eq(Mat3::from_rotation_z(1e-7), 1e-6));Whether no entry is NaN or infinite.
nabiassert(spatial::Mat3::IDENTITY.is_finite());