Mat23

nape.geom.Mat23 (final class)

2D Matrix class representing affine transformations:

[ a  b  tx ]
[ c  d  ty ]
[ 0  0  1  ]

Note that in AS3, flash.geom.Matrix has 'b' and 'c' swapped! so if you are converting between flash.geom.Matrix and nape.geom.Mat23 you should use the methods provided to avoid any mistakes with this.

Static Members

nape
rotation(angle: Float): Mat23

Construct a Mat23 representing a clockwise rotation.

[ cos angle  -sin angle  0 ]
[ sin angle   cos angle  0 ]
Name Type Description
angle Float The clockwise rotation in radians
Returns Description
Mat23 The rotation matrix.

nape
translation(tx: Float, ty: Float): Mat23

Construct a Mat23 representing a translation

[ 1  0  tx ]
[ 0  1  ty ]
Name Type Description
tx Float The x translation.
ty Float The y translation.
Returns Description
Mat23 The translation matrix.

nape
scale(sx: Float, sy: Float): Mat23

Construct a Mat23 representing a scaling

[ sx  0  0 ]
[ 0  sy  0 ]
Name Type Description
sx Float The x factor of scaling.
sy Float The y factor of scaling.
Returns Description
Mat23 The scaling matrix.

Instance Members

@private


nape
a: Float

The (1,1) entry in Mat23:

[ a  .  . ]
[ .  .  . ]

@default 1


nape
b: Float

The (1,2) entry in Mat23:

[ .  b  . ]
[ .  .  . ]

@default 0


nape
c: Float

The (2,1) entry in Mat23:

[ .  .  . ]
[ c  .  . ]

@default 0


nape
d: Float

The (2,2) entry in Mat23:

[ .  .  . ]
[ .  d  . ]

@default 1


nape
tx: Float

The (1,3) entry in Mat23 which represents x translation

[ .  .  tx ]
[ .  .  .  ]

@default 0


nape
ty: Float

The (2,3) entry in Mat23 which represents y translation

[ .  .  .  ]
[ .  .  ty ]

@default 0


nape
determinant: Float

(readonly) The determinant of this matrix.

This represents the factor of change in area for a region of the plane after transformation by matrix.

A determinant of 0 signifies that the matrix is not invertible.

A negative determinant signifies that for example, a clockwise wound polygon would be transformed into a counter-clockwise polygon.

@default 1


nape
copy(): Mat23

Produce copy of this Mat23

Returns Description
Mat23 The new Mat23 representing copy of this.

nape
set(matrix: Mat23): Mat23

Set values of matrix from another.

Name Type Description
matrix Mat23 The matrix to copy values from.
Returns Description
Mat23 A reference to this Mat23.

nape
setAs(?a: Float = 1.0, ?b: Float = 0.0, ?c: Float = 0.0, ?d: Float = 1.0, ?tx: Float = 0.0, ?ty: Float = 0.0): Mat23

Set values of matrix from numbers.

So that: mat.setAs(...) is semantically equivalent to: mat.set(new Mat23(...))

Name Type Default Description
a Float 1.0 The value to which the (1,1) entry will be set (default 1)
b Float 0.0 The value to which the (1,2) entry will be set (default 0)
c Float 0.0 The value to which the (2,1) entry will be set (default 0)
d Float 1.0 The value to which the (2,2) entry will be set (default 1)
tx Float 0.0 The value to which the (1,3) entry will be set (default 0)
ty Float 0.0 The value to which the (2,3) entry will be set (default 0)
Returns Description
Mat23 A reference to this Mat23.

nape
reset(): Mat23

Reset matrix to identity.

Equivalent to calling setAs with default argument values.

Returns Description
Mat23 A reference to this Mat23.

nape
singular(): Bool

Determine if the matrix is singular. This check is based on computing the condition number of the matrix by the Frobenius norm, and comparing against 2 / epsilon.

If matrix is singular, then inversion of the matrix cannot be performed

Returns Description
Bool True, if matrix is singular.

nape
inverse(): Mat23

Compute the inverse of this matrix, returning the inverse in a new Mat23 object.

The inverse is such that mat.concat(mat.inverse()) is the identity matrix, as well as mat.inverse().concat(mat)

Returns Description
Mat23 The inverse matrix.

nape
transpose(): Mat23

Compute the transpose of this matrix, returning the transpose in a new Mat23 object.

Technically speaking, we cannot transpose a matrix if the tx/ty values are non-zero as the implicit bottom row of matrix must be (0, 0, 1) so the tx/ty values of output matrix are set so that should the main 2x2 block of the matrix be orthogonal (Representing a rotation), then the transpose will be able to act as the matrix inverse.

var mat = Mat23.rotation(..).concat(Mat23.translation(...));
trace(mat.concat(mat.transpose())); // Identity matrix
trace(mat.concat(mat.inverse())); // Identity matrix

If the main 2x2 block of matrix is 'not' orthogonal, then the transpose will not be equal to the inverse.

Returns Description
Mat23 The transposed matrix.

nape
concat(matrix: Mat23): Mat23

Concatenate matrices (left-multiplication), returning new Mat23.

mat1.concat(mat2) is the transformation that first performs transformation represented by mat1, followed by transformation represented by mat2.

Name Type Description
matrix Mat23 Matrix to concatenate with.
Returns Description
Mat23 The result of the concatenation.

nape
transform(point: Vec2, ?noTranslation: Bool = false, ?weak: Bool = false): Vec2

Transform a Vec2 by this matrix in new Vec2.

The Vec2 object will be allocated form the global object pool.

Name Type Default Description
point Vec2 The Vec2 to transform by this matrix.
noTranslation Bool false If true, then the input Vec2 will be treat as a vector, rather than a point with the tx/ty values treat as 0. (default false)
weak Bool false If true, then the allocated Vec2 will be automatically released to global object pool when used as an argument to a Nape function.
Returns Description
Vec2 The result of the transformation as a newly allocated (possibly weak) Vec2. (default false)

nape
inverseTransform(point: Vec2, ?noTranslation: Bool = false, ?weak: Bool = false): Vec2

Perform inverse transformation with Vec2, returning new Vec2.

The matrix inverse will be performed implicitly and should this method be called many times for the same Mat23, it would be better to instead compute the matrix inverse only once.

The new Vec2 will be allocated from the global object pool.

Name Type Default Description
point Vec2 The Vec2 to transform.
noTranslation Bool false If true then the input Vec2 will be treat as a vector instead of a point, treating the tx/ty values of this Mat23 as though they were 0. (default false)
weak Bool false If true, then the allocated Vec2 will be automatically released to global object pool when used as an argument to a Nape function.
Returns Description
Vec2 The result of the transformation as a newly allocated (possibly weak) Vec2. (default false)

nape
toString(): String

@private

Returns
String

nape
equiorthogonal(): Bool

Determine if matrix is equiorthogonal

This is a term I invented after failing to find an existing name. It describes that this matrix maps circles into other circles (of not necessarigly the same radius). In otherwords the matrix can be decomposed into a rotation, translation and scaling of equal x/y factors.

This property is required for any Mat23 that is used to transform a Circle, or any Body containing a Circle, or to transform a Debug view.

This is a weaker property than orthogonality which describes a mapping to a circle of equal radius.

Mathematically speaking a matrix is equiorthogonal iff. transpose(M) * M = kI for some non-zero scalar k.

Returns Description
Bool True if matrix is equiorthogonal.

nape
orthogonal(): Bool

Determine if matrix is orthogonal

This property describes a matrix which maps circles into other circles of equal radius. In otherwords the matrix can be decomposed into a rotation and a translation.

Mathematically speaking a matrix is orthogonal iff. transpose(M) * M = I.

Returns Description
Bool True if matrix is orthogonal.

nape
equiorthogonalise(): Mat23

Equiorthogonalise matrix.

We do this by finding the 'nearest' orthogonal matrix; scaling the basis vectors of matrix to their mean length and applying an equal and opposite rotation to each basis vector to make them perpendicular.

Returns Description
Mat23 A reference to this Mat23.

nape
orthogonalise(): Mat23

Orthogonalise matrix.

We do this by finding the 'nearest' orthogonal matrix; normalising the basis vectors of matrix and applying an equal and opposite rotation to each basis vector to make them perpendicular.

Returns Description
Mat23 A reference to this Mat23.

nape
new(?a: Float = 1.0, ?b: Float = 0.0, ?c: Float = 0.0, ?d: Float = 1.0, ?tx: Float = 0.0, ?ty: Float = 0.0): Void

Construct new Mat23.

[ a  b  tx ]
[ c  d  ty ]
Name Type Default Description
a Float 1.0 The (1,1) entry in matrix (default 1)
b Float 0.0 The (1,2) entry in matrix (default 0)
c Float 0.0 The (2,1) entry in matrix (default 0)
d Float 1.0 The (2,2) entry in matrix (default 1)
tx Float 0.0 The (1,3) entry in matrix (default 0)
ty Float 0.0 The (2,3) entry in matrix (default 0)

Private Members

Metadata

Name Parameters
:final -