TransformationMatrix

Inheritance: java.lang.Object

public class TransformationMatrix

Represents 3x3 matrix | A B 0 | | C D 0 | | TX TY 1 |. Transforms coordinates in the following way: x1 = A*x + C*y + TX y1 = B*x + D*y + TY.

Constructors

ConstructorDescription
TransformationMatrix()Creates standard 1 to 1 matrix: [ A B C D TX TY ] = [ 1, 0, 0, 1, 0, 0]
TransformationMatrix(double[] matrixArray)Accepts a transformation matrix with following array representation: [ A B C D TX TY ]

Methods

MethodDescription
getA()Gets A transformation matrix value.
setA(double value)Sets A transformation matrix value.
getB()Gets B transformation matrix value.
setB(double value)Sets B transformation matrix value.
getC()Gets C transformation matrix value.
setC(double value)Sets C transformation matrix value.
getD()Gets D transformation matrix value.
setD(double value)Sets D transformation matrix value.
getTX()Gets TX transformation matrix value.
setTX(double value)Sets TX transformation matrix value.
getTY()Gets TY transformation matrix value.
setTY(double value)Sets TY transformation matrix value.
transform(double x, double y, double[] x1, double[] y1)Transforms x and y with the transformation matrix: x1 = A*x + C*y + TX; y1 = B*x + D*y + TY.
unTransform(double x1, double y1, double[] x, double[] y)Transforms back x1 and y1 and returns x and y before the transformation matrix.
unScale(double x1, double y1, double[] x, double[] y)Scales back x1 and y1 and returns x and y before the transformation matrix.
scale(double x, double y, double[] x1, double[] y1)Scales x and y with the transformation matrix: x1 = A*x + C*y; y1 = B*x + D*y.
multiply(TransformationMatrix matrix)Multiplies with another transformation matrix.
toArray()Allocates new array, copies the transformation matrix and returns it.
get(int index)Provides access to underlying array.

TransformationMatrix()

public TransformationMatrix()

Creates standard 1 to 1 matrix: [ A B C D TX TY ] = [ 1, 0, 0, 1, 0, 0]

TransformationMatrix(double[] matrixArray)

public TransformationMatrix(double[] matrixArray)

Accepts a transformation matrix with following array representation: [ A B C D TX TY ]

Parameters:

ParameterTypeDescription
matrixArraydouble[]Array with transformation matrix values, must have 6 elements.

getA()

public double getA()

Gets A transformation matrix value.

Returns: double - A transformation matrix value.

setA(double value)

public void setA(double value)

Sets A transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleA transformation matrix value.

getB()

public double getB()

Gets B transformation matrix value.

Returns: double - B transformation matrix value.

setB(double value)

public void setB(double value)

Sets B transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleB transformation matrix value.

getC()

public double getC()

Gets C transformation matrix value.

Returns: double - C transformation matrix value.

setC(double value)

public void setC(double value)

Sets C transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleC transformation matrix value.

getD()

public double getD()

Gets D transformation matrix value.

Returns: double - D transformation matrix value.

setD(double value)

public void setD(double value)

Sets D transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleD transformation matrix value.

getTX()

public double getTX()

Gets TX transformation matrix value.

Returns: double - TX transformation matrix value.

setTX(double value)

public void setTX(double value)

Sets TX transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleTX transformation matrix value.

getTY()

public double getTY()

Gets TY transformation matrix value.

Returns: double - TY transformation matrix value.

setTY(double value)

public void setTY(double value)

Sets TY transformation matrix value.

Parameters:

ParameterTypeDescription
valuedoubleTY transformation matrix value.

transform(double x, double y, double[] x1, double[] y1)

public void transform(double x, double y, double[] x1, double[] y1)

Transforms x and y with the transformation matrix: x1 = A*x + C*y + TX; y1 = B*x + D*y + TY.

Parameters:

ParameterTypeDescription
xdoubleOriginal x coordinate.
ydoubleOriginal y coordinate.
x1double[]Transformed x coordinate.
y1double[]Transformed y coordinate.

unTransform(double x1, double y1, double[] x, double[] y)

public void unTransform(double x1, double y1, double[] x, double[] y)

Transforms back x1 and y1 and returns x and y before the transformation matrix.

Parameters:

ParameterTypeDescription
x1doubleCoordinate x1.
y1doubleCoordinate y1.
xdouble[]Coordinate x transformed back.
ydouble[]Coordinate y transformed back.

unScale(double x1, double y1, double[] x, double[] y)

public void unScale(double x1, double y1, double[] x, double[] y)

Scales back x1 and y1 and returns x and y before the transformation matrix.

Parameters:

ParameterTypeDescription
x1doubleCoordinate x1
y1doubleCoordinate y1
xdouble[]Coordinate x scaled back.
ydouble[]Coordinate y scaled back.

scale(double x, double y, double[] x1, double[] y1)

public void scale(double x, double y, double[] x1, double[] y1)

Scales x and y with the transformation matrix: x1 = A*x + C*y; y1 = B*x + D*y.

Parameters:

ParameterTypeDescription
xdoubleOriginal x coordinate
ydoubleOriginal y coordinate.
x1double[]Coordinate x scaled.
y1double[]Coordinate y scaled.

multiply(TransformationMatrix matrix)

public TransformationMatrix multiply(TransformationMatrix matrix)

Multiplies with another transformation matrix. Doesn’t change original transformation matrix, returns a new TransformationMatrix object.

Parameters:

ParameterTypeDescription
matrixTransformationMatrixTransformation matrix to multiply with.

Returns: TransformationMatrix - New TransformationMatrix object.

toArray()

public double[] toArray()

Allocates new array, copies the transformation matrix and returns it.

Returns: double[] - TransformationMatrix in array form.

get(int index)

public double get(int index)

Provides access to underlying array.

Parameters:

ParameterTypeDescription
indexintIndex in transformation matrix array.

Returns: double - The element of underlying array by index.