APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.math

public final Class Affine2

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, com.badlogic.gdx.utils.GdxRuntimeException

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).
Author
vmilea

Field Summary

Modifier and TypeField and Description
public float
public float
public float
public float
public float
public float
private static final long

Constructor Summary

AccessConstructor and Description
public
Affine2()

Constructs an identity matrix.

public
Affine2(Affine2
The affine matrix to copy. This matrix will not be modified.
other
)

Constructs a matrix from the given affine matrix.

Method Summary

Modifier and TypeMethod and Description
public void
applyTo(Vector2 point)

Applies the affine transformation on a vector.

public float

Returns:

The determinant of this matrix.
det
()

Calculates the determinant of the matrix.

public Vector2

Returns:

Filled position.
getTranslation
(Vector2
Output vector.
position
)

Get the x-y translation component of the matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
idt
()

Sets this matrix to the identity matrix

public Affine2

Returns:

This matrix for the purpose of chaining operations.
inv
()

Inverts this matrix given that the determinant is != 0.

public boolean

Returns:

True if scale is 1 and rotation is 0.
isIdt
()

Check if this is an indentity matrix.

public boolean

Returns:

True if scale is 1 and rotation is 0.
isTranslation
()

Check if the this is a plain translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations together.
mul
(Affine2
Matrix to multiply by.
other
)

Postmultiplies this matrix with the provided matrix and stores the result in this matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
preMul
(Affine2
The other Matrix to multiply by
other
)

Premultiplies this matrix with the provided matrix and stores the result in this matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preRotate
(float
The angle in degrees
degrees
)

Premultiplies this matrix with a (counter-clockwise) rotation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preRotateRad
(float
The angle in radians
radians
)

Premultiplies this matrix with a (counter-clockwise) rotation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preScale
(float
The scale in the x-axis.
scaleX
,
float
The scale in the y-axis.
scaleY
)

Premultiplies this matrix with a scale matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preScale
(Vector2
The scale vector.
scale
)

Premultiplies this matrix with a scale matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preShear
(float
The shear in x direction.
shearX
,
float
The shear in y direction.
shearY
)

Premultiplies this matrix by a shear matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preShear
(Vector2
The shear vector.
shear
)

Premultiplies this matrix by a shear matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preTranslate
(float
The x-component of the translation vector.
x
,
float
The y-component of the translation vector.
y
)

Premultiplies this matrix by a translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
preTranslate
(Vector2
The translation vector.
trn
)

Premultiplies this matrix by a translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
rotate
(float
The angle in degrees
degrees
)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
rotateRad
(float
The angle in radians
radians
)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
scale
(float
The scale in the x-axis.
scaleX
,
float
The scale in the y-axis.
scaleY
)

Postmultiplies this matrix with a scale matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
scale
(Vector2
The scale vector.
scale
)

Postmultiplies this matrix with a scale matrix.

public Affine2

Returns:

This matrix for the purposes of chaining.
set
(Affine2
The affine matrix to copy.
other
)

Copies the values from the provided affine matrix to this matrix.

public Affine2

Returns:

This matrix for the purposes of chaining.
set
(Matrix3
The matrix to copy, assumed to be an affine transformation.
matrix
)

Copies the values from the provided matrix to this matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
set
(Matrix4
The source matrix, assumed to be an affine transformation within XY plane. This matrix will not be modified.
matrix
)

Copies the 2D transformation components from the provided 4x4 matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToProduct
(Affine2
Left matrix.
l
,
Affine2
Right matrix.
r
)

Sets this matrix to the product of two matrices.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToRotation
(float
The angle in degrees.
degrees
)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToRotation
(float
The angle cosine.
cos
,
float
The angle sine.
sin
)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToRotationRad
(float
The angle in radians.
radians
)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToScaling
(float
The scale in x.
scaleX
,
float
The scale in y.
scaleY
)

Sets this matrix to a scaling matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToScaling
(Vector2
The scale vector.
scale
)

Sets this matrix to a scaling matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToShearing
(float
The shear in x direction.
shearX
,
float
The shear in y direction.
shearY
)

Sets this matrix to a shearing matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToShearing
(Vector2
The shear vector.
shear
)

Sets this matrix to a shearing matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTranslation
(float
The translation in x
x
,
float
The translation in y
y
)

Sets this matrix to a translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTranslation
(Vector2
The translation vector.
trn
)

Sets this matrix to a translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnRotRadScl
(float
The translation in x.
x
,
float
The translation in y.
y
,
float
The angle in radians.
radians
,
float
The scale in y.
scaleX
,
float
The scale in x.
scaleY
)

Sets this matrix to a concatenation of translation, rotation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnRotRadScl
(Vector2
The translation vector.
trn
,
float
The angle in radians.
radians
,
Vector2
The scale vector.
scale
)

Sets this matrix to a concatenation of translation, rotation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnRotScl
(float
The translation in x.
x
,
float
The translation in y.
y
,
float
The angle in degrees.
degrees
,
float
The scale in y.
scaleX
,
float
The scale in x.
scaleY
)

Sets this matrix to a concatenation of translation, rotation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnRotScl
(Vector2
The translation vector.
trn
,
float
The angle in degrees.
degrees
,
Vector2
The scale vector.
scale
)

Sets this matrix to a concatenation of translation, rotation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnScl
(float
The translation in x.
x
,
float
The translation in y.
y
,
float
The scale in y.
scaleX
,
float
The scale in x.
scaleY
)

Sets this matrix to a concatenation of translation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining operations.
setToTrnScl
(Vector2
The translation vector.
trn
,
Vector2
The scale vector.
scale
)

Sets this matrix to a concatenation of translation and scale.

public Affine2

Returns:

This matrix for the purpose of chaining.
shear
(float
The shear in x direction.
shearX
,
float
The shear in y direction.
shearY
)

Postmultiplies this matrix by a shear matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
shear
(Vector2
The shear vector.
shear
)

Postmultiplies this matrix by a shear matrix.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Affine2

Returns:

This matrix for the purpose of chaining.
translate
(float
The x-component of the translation vector.
x
,
float
The y-component of the translation vector.
y
)

Postmultiplies this matrix by a translation matrix.

public Affine2

Returns:

This matrix for the purpose of chaining.
translate
(Vector2
The translation vector.
trn
)

Postmultiplies this matrix by a translation matrix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

m00back to summary
public float m00
m01back to summary
public float m01
m02back to summary
public float m02
m10back to summary
public float m10
m11back to summary
public float m11
m12back to summary
public float m12
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Affine2back to summary
public Affine2()

Constructs an identity matrix.

Affine2back to summary
public Affine2(Affine2 other)

Constructs a matrix from the given affine matrix.

Parameters
other:Affine2

The affine matrix to copy. This matrix will not be modified.

Method Detail

applyToback to summary
public void applyTo(Vector2 point)

Applies the affine transformation on a vector.

detback to summary
public float det()

Calculates the determinant of the matrix.

Returns:float

The determinant of this matrix.

getTranslationback to summary
public Vector2 getTranslation(Vector2 position)

Get the x-y translation component of the matrix.

Parameters
position:Vector2

Output vector.

Returns:Vector2

Filled position.

idtback to summary
public Affine2 idt()

Sets this matrix to the identity matrix

Returns:Affine2

This matrix for the purpose of chaining operations.

invback to summary
public Affine2 inv()

Inverts this matrix given that the determinant is != 0.

Returns:Affine2

This matrix for the purpose of chaining operations.

Exceptions
GdxRuntimeException:
if the matrix is singular (not invertible)
isIdtback to summary
public boolean isIdt()

Check if this is an indentity matrix.

Returns:boolean

True if scale is 1 and rotation is 0.

isTranslationback to summary
public boolean isTranslation()

Check if the this is a plain translation matrix.

Returns:boolean

True if scale is 1 and rotation is 0.

mulback to summary
public Affine2 mul(Affine2 other)

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:Affine2

Matrix to multiply by.

Returns:Affine2

This matrix for the purpose of chaining operations together.

preMulback to summary
public Affine2 preMul(Affine2 other)

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:Affine2

The other Matrix to multiply by

Returns:Affine2

This matrix for the purpose of chaining operations.

preRotateback to summary
public Affine2 preRotate(float degrees)

Premultiplies this matrix with a (counter-clockwise) rotation matrix.

Parameters
degrees:float

The angle in degrees

Returns:Affine2

This matrix for the purpose of chaining.

preRotateRadback to summary
public Affine2 preRotateRad(float radians)

Premultiplies this matrix with a (counter-clockwise) rotation matrix.

Parameters
radians:float

The angle in radians

Returns:Affine2

This matrix for the purpose of chaining.

preScaleback to summary
public Affine2 preScale(float scaleX, float scaleY)

Premultiplies this matrix with a scale matrix.

Parameters
scaleX:float

The scale in the x-axis.

scaleY:float

The scale in the y-axis.

Returns:Affine2

This matrix for the purpose of chaining.

preScaleback to summary
public Affine2 preScale(Vector2 scale)

Premultiplies this matrix with a scale matrix.

Parameters
scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining.

preShearback to summary
public Affine2 preShear(float shearX, float shearY)

Premultiplies this matrix by a shear matrix.

Parameters
shearX:float

The shear in x direction.

shearY:float

The shear in y direction.

Returns:Affine2

This matrix for the purpose of chaining.

preShearback to summary
public Affine2 preShear(Vector2 shear)

Premultiplies this matrix by a shear matrix.

Parameters
shear:Vector2

The shear vector.

Returns:Affine2

This matrix for the purpose of chaining.

preTranslateback to summary
public Affine2 preTranslate(float x, float y)

Premultiplies this matrix by a translation matrix.

Parameters
x:float

The x-component of the translation vector.

y:float

The y-component of the translation vector.

Returns:Affine2

This matrix for the purpose of chaining.

preTranslateback to summary
public Affine2 preTranslate(Vector2 trn)

Premultiplies this matrix by a translation matrix.

Parameters
trn:Vector2

The translation vector.

Returns:Affine2

This matrix for the purpose of chaining.

rotateback to summary
public Affine2 rotate(float degrees)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

Parameters
degrees:float

The angle in degrees

Returns:Affine2

This matrix for the purpose of chaining.

rotateRadback to summary
public Affine2 rotateRad(float radians)

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

Parameters
radians:float

The angle in radians

Returns:Affine2

This matrix for the purpose of chaining.

scaleback to summary
public Affine2 scale(float scaleX, float scaleY)

Postmultiplies this matrix with a scale matrix.

Parameters
scaleX:float

The scale in the x-axis.

scaleY:float

The scale in the y-axis.

Returns:Affine2

This matrix for the purpose of chaining.

scaleback to summary
public Affine2 scale(Vector2 scale)

Postmultiplies this matrix with a scale matrix.

Parameters
scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining.

setback to summary
public Affine2 set(Affine2 other)

Copies the values from the provided affine matrix to this matrix.

Parameters
other:Affine2

The affine matrix to copy.

Returns:Affine2

This matrix for the purposes of chaining.

setback to summary
public Affine2 set(Matrix3 matrix)

Copies the values from the provided matrix to this matrix.

Parameters
matrix:Matrix3

The matrix to copy, assumed to be an affine transformation.

Returns:Affine2

This matrix for the purposes of chaining.

setback to summary
public Affine2 set(Matrix4 matrix)

Copies the 2D transformation components from the provided 4x4 matrix. The values are mapped as follows:

     [  M00  M01  M03  ]
     [  M10  M11  M13  ]
     [   0    0    1   ]
Parameters
matrix:Matrix4

The source matrix, assumed to be an affine transformation within XY plane. This matrix will not be modified.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToProductback to summary
public Affine2 setToProduct(Affine2 l, Affine2 r)

Sets this matrix to the product of two matrices.

Parameters
l:Affine2

Left matrix.

r:Affine2

Right matrix.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToRotationback to summary
public Affine2 setToRotation(float degrees)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

Parameters
degrees:float

The angle in degrees.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToRotationback to summary
public Affine2 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.

Parameters
cos:float

The angle cosine.

sin:float

The angle sine.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToRotationRadback to summary
public Affine2 setToRotationRad(float radians)

Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis.

Parameters
radians:float

The angle in radians.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToScalingback to summary
public Affine2 setToScaling(float scaleX, float scaleY)

Sets this matrix to a scaling matrix.

Parameters
scaleX:float

The scale in x.

scaleY:float

The scale in y.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToScalingback to summary
public Affine2 setToScaling(Vector2 scale)

Sets this matrix to a scaling matrix.

Parameters
scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToShearingback to summary
public Affine2 setToShearing(float shearX, float shearY)

Sets this matrix to a shearing matrix.

Parameters
shearX:float

The shear in x direction.

shearY:float

The shear in y direction.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToShearingback to summary
public Affine2 setToShearing(Vector2 shear)

Sets this matrix to a shearing matrix.

Parameters
shear:Vector2

The shear vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTranslationback to summary
public Affine2 setToTranslation(float x, float y)

Sets this matrix to a translation matrix.

Parameters
x:float

The translation in x

y:float

The translation in y

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTranslationback to summary
public Affine2 setToTranslation(Vector2 trn)

Sets this matrix to a translation matrix.

Parameters
trn:Vector2

The translation vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnRotRadSclback to summary
public Affine2 setToTrnRotRadScl(float x, float y, float radians, float scaleX, float scaleY)

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:float

The translation in x.

y:float

The translation in y.

radians:float

The angle in radians.

scaleX:float

The scale in y.

scaleY:float

The scale in x.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnRotRadSclback to summary
public Affine2 setToTrnRotRadScl(Vector2 trn, float radians, Vector2 scale)

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:Vector2

The translation vector.

radians:float

The angle in radians.

scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnRotSclback to summary
public Affine2 setToTrnRotScl(float x, float y, float degrees, float scaleX, float scaleY)

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:float

The translation in x.

y:float

The translation in y.

degrees:float

The angle in degrees.

scaleX:float

The scale in y.

scaleY:float

The scale in x.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnRotSclback to summary
public Affine2 setToTrnRotScl(Vector2 trn, float degrees, Vector2 scale)

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:Vector2

The translation vector.

degrees:float

The angle in degrees.

scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnSclback to summary
public Affine2 setToTrnScl(float x, float y, float scaleX, float scaleY)

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:float

The translation in x.

y:float

The translation in y.

scaleX:float

The scale in y.

scaleY:float

The scale in x.

Returns:Affine2

This matrix for the purpose of chaining operations.

setToTrnSclback to summary
public Affine2 setToTrnScl(Vector2 trn, Vector2 scale)

Sets this matrix to a concatenation of translation and scale. It is a more efficient form for: idt().translate(trn).scale(scale)

Parameters
trn:Vector2

The translation vector.

scale:Vector2

The scale vector.

Returns:Affine2

This matrix for the purpose of chaining operations.

shearback to summary
public Affine2 shear(float shearX, float shearY)

Postmultiplies this matrix by a shear matrix.

Parameters
shearX:float

The shear in x direction.

shearY:float

The shear in y direction.

Returns:Affine2

This matrix for the purpose of chaining.

shearback to summary
public Affine2 shear(Vector2 shear)

Postmultiplies this matrix by a shear matrix.

Parameters
shear:Vector2

The shear vector.

Returns:Affine2

This matrix for the purpose of chaining.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
translateback to summary
public Affine2 translate(float x, float y)

Postmultiplies this matrix by a translation matrix.

Parameters
x:float

The x-component of the translation vector.

y:float

The y-component of the translation vector.

Returns:Affine2

This matrix for the purpose of chaining.

translateback to summary
public Affine2 translate(Vector2 trn)

Postmultiplies this matrix by a translation matrix.

Parameters
trn:Vector2

The translation vector.

Returns:Affine2

This matrix for the purpose of chaining.