Struct math2d::Matrix3x2f

source ·
#[repr(C)]
pub struct Matrix3x2f { pub a: f32, pub b: f32, pub c: f32, pub d: f32, pub x: f32, pub y: f32, }
Expand description

2D Affine Transformation Matrix.

Mathematically you can think of this matrix as if it were the following:

[a, b, 0]
[c, d, 0]
[x, y, 1]

Composing matrices

Affine transformations are performed in “Row-Major” order. What this means, if you’re familiar with linear algebra, is that when you compose multiple affine transformations together, the matrix representing the set of operations that should happen “first” must be the left hand operand of the multiplication operator.

This is also why points and vectors are the left-hand operand when multiplied with matrices.

Fields§

§a: f32

Horizontal scaling / cosine of rotation

§b: f32

Vertical shear / sine of rotation

§c: f32

Horizontal shear / negative sine of rotation

§d: f32

Vertical scaling / cosine of rotation

§x: f32

Horizontal translation (always orthogonal regardless of rotation)

§y: f32

Vertical translation (always orthogonal regardless of rotation)

Implementations§

The 2D affine identity matrix.

Construct the matrix from an array of the row values.

Constructs the matrix from a slice of 6 values as [a, b, c, d, x, y].

Panics if values does not contain exactly 6 elements.

Constructs the matrix from a tuple of 6 values as (a, b, c, d, x, y).

Creates an affine translation matrix that translates points by the passed vector. The linear part of the matrix is the identity.

Example Translation

Read More

Creates a scaling matrix that performs scaling around a specified point of origin. This is equivalent to translating the center point back to the origin, scaling around the origin by the scaling value, and then translating the center point back to its original location.

Example Scaling

Read More

Creates a rotation matrix that performs rotation around a specified point of origin. This is equivalent to translating the center point back to the origin, rotating around the origin by the specified angle, and then translating the center point back to its original location.

Example Rotation

Read More

Creates a matrix that skews an object by a tangent angle around the center point.

Example Effect of Skewing

Read More

Computes the transpose of the linear part of this matrix i.e. swap(b, c).

Returns the determinant of the matrix. Since this matrix is conceptually 3x3, and the bottom-right element is always 1, this value works out to be a * d - b * c.

Determines if the inverse or try_inverse functions would succeed if called. A matrix is invertible if its determinant is nonzero. Since we’re dealing with floats, we check that the absolute value of the determinant is greater than f32::EPSILON.

Calculates the inverse of this matrix. Panics if the matrix is not invertible (see above).

Calculates the inverse of the matrix. Returns None if the determinant is less than f32::EPSILON.

Performs the inverse of the matrix without checking for invertibility.

WARNING: If this matrix is not invertible, you may get NaN or INF!

Compose a matrix from a scaling, rotation, and translation value (combined in that order).

Decomposes a simple affine transformation into its scaling, rotation, and translation parts.

A more explicit way to do point * matrix, while also allowing any type that may be converted into a Point2F with a From/Into impl.

A more explicit way to do vec * matrix, while also allowing any type that may be converted into a Vector2F with a From/Into impl.

Returns this matrix as a 3x3 float array using the mathematical form described above.

Returns the matrix as a 3x3 float array in column major form, i.e. the transpose of the row-major version.

Checks if two matrices are approximately equal given an epsilon value.

Checks if this matrix is equal to the identity matrix within 1e-5

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.