Package arc.math
Class Affine2
java.lang.Object
arc.math.Affine2
A specialized 3x3 matrix that can represent sequences of 2D translations, scales, flips, rotations, and shears. Affine transformations preserve straight lines, and
parallel lines remain parallel after the transformation. Operations on affine matrices are faster because the last row can
always be assumed (0, 0, 1).
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Applies the affine transformation on a vector.float
det()
Calculates the determinant of the matrix.getTranslation
(Vec2 position) Get the x-y translation component of the matrix.idt()
Sets this matrix to the identity matrixinv()
Inverts this matrix given that the determinant is != 0.boolean
isIdt()
Check if this is an indentity matrix.boolean
Check if the this is a plain translation matrix.Postmultiplies this matrix with the provided matrix and stores the result in this matrix.Premultiplies this matrix with the provided matrix and stores the result in this matrix.preRotate
(float degrees) Premultiplies this matrix with a (counter-clockwise) rotation matrix.preRotateRad
(float radians) Premultiplies this matrix with a (counter-clockwise) rotation matrix.preScale
(float scaleX, float scaleY) Premultiplies this matrix with a scale matrix.Premultiplies this matrix with a scale matrix.preShear
(float shearX, float shearY) Premultiplies this matrix by a shear matrix.Premultiplies this matrix by a shear matrix.preTranslate
(float x, float y) Premultiplies this matrix by a translation matrix.preTranslate
(Vec2 trn) Premultiplies this matrix by a translation matrix.rotate
(float degrees) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.rotateRad
(float radians) Postmultiplies this matrix with a (counter-clockwise) rotation matrix.scale
(float scaleX, float scaleY) Postmultiplies this matrix with a scale matrix.Postmultiplies this matrix with a scale matrix.Copies the values from the provided affine matrix to this matrix.Copies the values from the provided matrix to this matrix.setToProduct
(Affine2 l, Affine2 r) Sets this matrix to the product of two matrices.setToRotation
(float degrees) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToRotation
(float cos, float sin) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToRotationRad
(float radians) Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.setToScaling
(float scaleX, float scaleY) Sets this matrix to a scaling matrix.setToScaling
(Vec2 scale) Sets this matrix to a scaling matrix.setToShearing
(float shearX, float shearY) Sets this matrix to a shearing matrix.setToShearing
(Vec2 shear) Sets this matrix to a shearing matrix.setToTranslation
(float x, float y) Sets this matrix to a translation matrix.setToTranslation
(Vec2 trn) Sets this matrix to a translation matrix.setToTrnRotRadScl
(float x, float y, float radians, float scaleX, float scaleY) Sets this matrix to a concatenation of translation, rotation and scale.setToTrnRotRadScl
(Vec2 trn, float radians, Vec2 scale) Sets this matrix to a concatenation of translation, rotation and scale.setToTrnRotScl
(float x, float y, float degrees, float scaleX, float scaleY) Sets this matrix to a concatenation of translation, rotation and scale.setToTrnRotScl
(Vec2 trn, float degrees, Vec2 scale) Sets this matrix to a concatenation of translation, rotation and scale.setToTrnScl
(float x, float y, float scaleX, float scaleY) Sets this matrix to a concatenation of translation and scale.setToTrnScl
(Vec2 trn, Vec2 scale) Sets this matrix to a concatenation of translation and scale.shear
(float shearX, float shearY) Postmultiplies this matrix by a shear matrix.Postmultiplies this matrix by a shear matrix.toString()
translate
(float x, float y) Postmultiplies this matrix by a translation matrix.Postmultiplies this matrix by a translation matrix.
-
Field Details
-
m00
public float m00 -
m01
public float m01 -
m02
public float m02 -
m10
public float m10 -
m11
public float m11 -
m12
public float m12
-
-
Constructor Details
-
Affine2
public Affine2()Constructs an identity matrix. -
Affine2
Constructs a matrix from the given affine matrix.- Parameters:
other
- The affine matrix to copy. This matrix will not be modified.
-
-
Method Details
-
idt
Sets this matrix to the identity matrix- Returns:
- This matrix for the purpose of chaining operations.
-
set
Copies the values from the provided affine matrix to this matrix.- Parameters:
other
- The affine matrix to copy.- Returns:
- This matrix for the purposes of chaining.
-
set
Copies the values from the provided matrix to this matrix.- Parameters:
matrix
- The matrix to copy, assumed to be an affine transformation.- Returns:
- This matrix for the purposes of chaining.
-
setToTranslation
Sets this matrix to a translation matrix.- Parameters:
x
- The translation in xy
- The translation in y- Returns:
- This matrix for the purpose of chaining operations.
-
setToTranslation
Sets this matrix to a translation matrix.- Parameters:
trn
- The translation vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToScaling
Sets this matrix to a scaling matrix.- Parameters:
scaleX
- The scale in x.scaleY
- The scale in y.- Returns:
- This matrix for the purpose of chaining operations.
-
setToScaling
Sets this matrix to a scaling matrix.- Parameters:
scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToRotation
Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.- Parameters:
degrees
- The angle in degrees.- Returns:
- This matrix for the purpose of chaining operations.
-
setToRotationRad
Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.- Parameters:
radians
- The angle in radians.- Returns:
- This matrix for the purpose of chaining operations.
-
setToRotation
Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.- Parameters:
cos
- The angle cosine.sin
- The angle sine.- Returns:
- This matrix for the purpose of chaining operations.
-
setToShearing
Sets this matrix to a shearing matrix.- Parameters:
shearX
- The shear in x direction.shearY
- The shear in y direction.- Returns:
- This matrix for the purpose of chaining operations.
-
setToShearing
Sets this matrix to a shearing matrix.- Parameters:
shear
- The shear vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnRotScl
Sets this matrix to a concatenation of translation, rotation and scale. It is a more efficient form for:idt().translate(x, y).rotate(degrees).scale(scaleX, scaleY)
- Parameters:
x
- The translation in x.y
- The translation in y.degrees
- The angle in degrees.scaleX
- The scale in y.scaleY
- The scale in x.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnRotScl
Sets this matrix to a concatenation of translation, rotation and scale. It is a more efficient form for:idt().translate(trn).rotate(degrees).scale(scale)
- Parameters:
trn
- The translation vector.degrees
- The angle in degrees.scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnRotRadScl
Sets this matrix to a concatenation of translation, rotation and scale. It is a more efficient form for:idt().translate(x, y).rotateRad(radians).scale(scaleX, scaleY)
- Parameters:
x
- The translation in x.y
- The translation in y.radians
- The angle in radians.scaleX
- The scale in y.scaleY
- The scale in x.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnRotRadScl
Sets this matrix to a concatenation of translation, rotation and scale. It is a more efficient form for:idt().translate(trn).rotateRad(radians).scale(scale)
- Parameters:
trn
- The translation vector.radians
- The angle in radians.scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnScl
Sets this matrix to a concatenation of translation and scale. It is a more efficient form for:idt().translate(x, y).scale(scaleX, scaleY)
- Parameters:
x
- The translation in x.y
- The translation in y.scaleX
- The scale in y.scaleY
- The scale in x.- Returns:
- This matrix for the purpose of chaining operations.
-
setToTrnScl
Sets this matrix to a concatenation of translation and scale. It is a more efficient form for:idt().translate(trn).scale(scale)
- Parameters:
trn
- The translation vector.scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining operations.
-
setToProduct
Sets this matrix to the product of two matrices.- Parameters:
l
- Left matrix.r
- Right matrix.- Returns:
- This matrix for the purpose of chaining operations.
-
inv
Inverts this matrix given that the determinant is != 0.- Returns:
- This matrix for the purpose of chaining operations.
- Throws:
ArcRuntimeException
- if the matrix is singular (not invertible)
-
mul
Postmultiplies this matrix with the provided matrix and stores the result in this matrix. For example:A.mul(B) results in A := AB
- Parameters:
other
- Matrix to multiply by.- Returns:
- This matrix for the purpose of chaining operations together.
-
preMul
Premultiplies this matrix with the provided matrix and stores the result in this matrix. For example:A.preMul(B) results in A := BA
- Parameters:
other
- The other Matrix to multiply by- Returns:
- This matrix for the purpose of chaining operations.
-
translate
Postmultiplies this matrix by a translation matrix.- Parameters:
x
- The x-component of the translation vector.y
- The y-component of the translation vector.- Returns:
- This matrix for the purpose of chaining.
-
translate
Postmultiplies this matrix by a translation matrix.- Parameters:
trn
- The translation vector.- Returns:
- This matrix for the purpose of chaining.
-
preTranslate
Premultiplies this matrix by a translation matrix.- Parameters:
x
- The x-component of the translation vector.y
- The y-component of the translation vector.- Returns:
- This matrix for the purpose of chaining.
-
preTranslate
Premultiplies this matrix by a translation matrix.- Parameters:
trn
- The translation vector.- Returns:
- This matrix for the purpose of chaining.
-
scale
Postmultiplies this matrix with a scale matrix.- Parameters:
scaleX
- The scale in the x-axis.scaleY
- The scale in the y-axis.- Returns:
- This matrix for the purpose of chaining.
-
scale
Postmultiplies this matrix with a scale matrix.- Parameters:
scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining.
-
preScale
Premultiplies this matrix with a scale matrix.- Parameters:
scaleX
- The scale in the x-axis.scaleY
- The scale in the y-axis.- Returns:
- This matrix for the purpose of chaining.
-
preScale
Premultiplies this matrix with a scale matrix.- Parameters:
scale
- The scale vector.- Returns:
- This matrix for the purpose of chaining.
-
rotate
Postmultiplies this matrix with a (counter-clockwise) rotation matrix.- Parameters:
degrees
- The angle in degrees- Returns:
- This matrix for the purpose of chaining.
-
rotateRad
Postmultiplies this matrix with a (counter-clockwise) rotation matrix.- Parameters:
radians
- The angle in radians- Returns:
- This matrix for the purpose of chaining.
-
preRotate
Premultiplies this matrix with a (counter-clockwise) rotation matrix.- Parameters:
degrees
- The angle in degrees- Returns:
- This matrix for the purpose of chaining.
-
preRotateRad
Premultiplies this matrix with a (counter-clockwise) rotation matrix.- Parameters:
radians
- The angle in radians- Returns:
- This matrix for the purpose of chaining.
-
shear
Postmultiplies this matrix by a shear matrix.- Parameters:
shearX
- The shear in x direction.shearY
- The shear in y direction.- Returns:
- This matrix for the purpose of chaining.
-
shear
Postmultiplies this matrix by a shear matrix.- Parameters:
shear
- The shear vector.- Returns:
- This matrix for the purpose of chaining.
-
preShear
Premultiplies this matrix by a shear matrix.- Parameters:
shearX
- The shear in x direction.shearY
- The shear in y direction.- Returns:
- This matrix for the purpose of chaining.
-
preShear
Premultiplies this matrix by a shear matrix.- Parameters:
shear
- The shear vector.- Returns:
- This matrix for the purpose of chaining.
-
det
public float det()Calculates the determinant of the matrix.- Returns:
- The determinant of this matrix.
-
getTranslation
Get the x-y translation component of the matrix.- Parameters:
position
- Output vector.- Returns:
- Filled position.
-
isTranslation
public boolean isTranslation()Check if the this is a plain translation matrix.- Returns:
- True if scale is 1 and rotation is 0.
-
isIdt
public boolean isIdt()Check if this is an indentity matrix.- Returns:
- True if scale is 1 and rotation is 0.
-
applyTo
Applies the affine transformation on a vector. -
toString
-