Creates a matrix from inputs in the form,
Static constructor methods are also available. See Mat33.scaling2D, Mat33.zRotation, Mat33.translation, and Mat33.fromCSSMatrix.
Readonly
a1Readonly
a2Readonly
a3Readonly
b1Readonly
b2Readonly
b3Readonly
c1Readonly
c2Readonly
c3Static
identityThe 3x3 identity matrix.
Returns true iff this = other ± fuzz
Right-multiplies this by other
.
See also transformVec3 and transformVec2.
Example:
import {Mat33, Vec2} from '@js-draw/math'; console.log(Mat33.identity.rightMul(Mat33.identity)); // Create a matrix by right multiplying. const scaleThenRotate = // The resultant matrix first scales by a factor of two Mat33.scaling2D(2).rightMul( // ...then rotates by pi/4 radians = 45 degrees. Mat33.zRotation(Math.PI / 4) ); console.log(scaleThenRotate); // Use scaleThenRotate to scale then rotate a vector. console.log(scaleThenRotate.transformVec2(Vec2.unitX));
result[0] = top left element
result[1] = element at row zero, column 1
...
Example:
import { Mat33 } from '@js-draw/math'; console.log( new Mat33( 1, 2, 3, 4, 5, 6, 7, 8, 9, ) );
Applies this as an affine transformation to the given vector.
Returns a transformed version of other
.
Unlike transformVec3, this does translate the given vector.
Static
fromCSSMatrixStatic
ofStatic
scaling2DStatic
translationStatic
zCreates a matrix for rotating Vec2
s about center
by some number of radians
.
For this function, Vec2s are considered to be points in 2D space.
For example,
import { Mat33, Vec2 } from '@js-draw/math'; const halfCircle = Math.PI; // PI radians = 180 degrees = 1/2 circle const center = Vec2.of(1, 1); // The point (1,1) const rotationMatrix = Mat33.zRotation(halfCircle, center); console.log( 'Rotating (0,0) 180deg about', center, 'results in', // Rotates (0,0) rotationMatrix.transformVec2(Vec2.zero), );
Represents a three dimensional linear transformation or a two-dimensional affine transformation. (An affine transformation scales/rotates/shears and translates while a linear transformation just scales/rotates/shears).
In addition to other matrices, Mat33s can be used to transform Vec3s and Vec2s.
For example, to move the point (1,1) by 5 units to the left and 6 units up,
This
moveLeftAndUp
matrix could then translate (move) a Vec2 using Mat33.transformVec2:It's also possible to create transformation matrices that scale and rotate. A single transform matrix can be created from multiple using matrix multiplication (see Mat33.rightMul):