Creates a 3x3 transformation matrix.
The constructor specifies the 9 entries of the matrix. Conceptually, the matrix looks like:
M00 M10 M20
M01 M11 M21
M02 M12 M22
Gets the determinant of the matrix.
Creates a transform matrix that transforms the geometry from one coordinate system
to another while keeping the geometry in the same position.
In other words, if the geometry is described relative to planeFrom
, after
applying this translation, it will be in the same position but described relative to planeTo
.
import { Plane, Point, Transform, Vector } from 'shapetypes';
// Setup the transformation
const from = new Plane(new Point(3, 4), Vector.worldX());
const to = Plane.worldXY();
const tran = Transform.changeBasis(from, to);
// Change the point's coordinates from the `from` plane to the `to` plane.
const p = new Point(1, 2);
const after = tran.transformPoint(p);
console.log(after.toString());
// => [4,6]
The coordinate system the geometry is currently described in.
The coordinate system to describe the geometry in.
Creates a transform matrix that moves the geometry from one plane to another.
The resulting geometry will be in the same place relative to planeTo
as it was relative to planeFrom
.
import { Plane, Point, Transform, Vector } from 'shapetypes';
// Setup the transformation
const from = new Plane(new Point(3, 4), Vector.worldX());
const to = Plane.worldXY();
const tran = Transform.planeToPlane(from, to);
// Move point so it is in the same place relative to plane `to` as it was for `from`
const p = new Point(4, 6);
const after = tran.transformPoint(p);
console.log(after.toString());
// => (1,2)
Creates a transform matrix that rotates an object about a point.
The angle of rotation (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.
The pivot point for rotation. If undefined, the object will be rotated about 0,0.
Creates a transform matrix that scales the geometry by a specified amount along the x- and y-axis.
The amount to scale the object along the x-axis. If less than 1, the object will shrink. If greater than 1, it will grow.
The amount to scale the object along the y-axis. If undefined, uses value from x
.
The center of scaling. All objects will shrink towards and grow away from this point. If undefined, it will use 0,0.
Checks whether another transform matrix has exactly the same values. Returns true if it does.
The matrix to compare against.
Inverts the matrix and returns the resulting matrix. Generally, applying the inverse matrix to an object will undo the impact of the original matrix. So if the original matrix rotated the object 90 degrees, the inverted matrix will rotate the object 90 degrees in the opposite direction.
If the inversion was successful, it will contain the inverted matrix. Otherwise contains the original matrix.
If the inversion was successful, it will be true
.
Gets the matrix as a string in the format: [M00,M10,M20,M01,M11,M21,M02,M12,M22]
.
Creates a copy of the Transform matrix with certain values replaced.
The new value for M00. If undefined, it will use the existing value in the matrix.
The new value for M10. If undefined, it will use the existing value in the matrix.
The new value for M20. If undefined, it will use the existing value in the matrix.
The new value for M01. If undefined, it will use the existing value in the matrix.
The new value for M11. If undefined, it will use the existing value in the matrix.
The new value for M21. If undefined, it will use the existing value in the matrix.
The new value for M02. If undefined, it will use the existing value in the matrix.
The new value for M12. If undefined, it will use the existing value in the matrix.
The new value for M22. If undefined, it will use the existing value in the matrix.
Generated using TypeDoc
A 3x3 transformation matrix that is used to rotate, scale, and translate geometry.
In many cases, you don't need to create this transformation matrix yourself, you can instead use the transformation functions available to all Geometry objects. That said, in some cases, you may still want to create your own matrix, particularly if you're doing your own custom transformations, or you're applying the same transformation many times. All geometry objects have a method to apply a transformation matrix (see: Vector.transform as an example).
Example
import { Transform, Vector } from 'shapetypes'; // Create a new vecctor const vector = new Vector(3, 4); console.log(vector.length); // => 5 // Scale vector using a transform matrix const matrix = Transform.scale(2); const scaled = vector.transform(matrix); console.log(vector.length); // => 10 // Scale vector using the direct method const otherScaled = vector.scale(2); console.log(otherScaled.length); // => 10