Class Matrix

• public final class Matrix
extends Object
A 2x3 "Postscript style" coordinate matrix (a 2D transformation and shift).

Synchronization

These objects are immutable.

• Field Summary

Fields
Modifier and Type Field Description
double a
double b
double c
double d
static Matrix IDENTITY_MATRIX
a constant Matrix representing the identity transformation
double tx
double ty
• Constructor Summary

Constructors
Constructor Description
Matrix​(double[] matrix)
Creates a matrix from either a 4 or 6 element array representing a matrix.
Matrix​(double a, double b, double c, double d, double tx, double ty)
• Method Summary

All Methods
Modifier and Type Method Description
void applyToPoint​(Point p)
computes p * this and returns the result in p
double applyToXYGetX​(double x, double y)
computes [x y] * this and returns the resulting x value
double applyToXYGetY​(double x, double y)
computes [x y] * this and returns the resulting y value
boolean isIdentity()
Returns true iff this is very close to representing the identity transformation.
boolean isInverse​(Matrix inverse)
Checks whether 'inverse' is the inverse of this matrix.
Matrix multiply​(double multiplier)
Computes this * multiplier and returns the resulting matrix.
Matrix multiply​(Matrix multiplier)
Computes this * multiplier and returns the resulting matrix.
• Field Detail

• IDENTITY_MATRIX

public static final Matrix IDENTITY_MATRIX
a constant Matrix representing the identity transformation
• a

public final double a
• b

public final double b
• c

public final double c
• d

public final double d
• tx

public final double tx
• ty

public final double ty
• Constructor Detail

• Matrix

public Matrix​(double[] matrix)
Creates a matrix from either a 4 or 6 element array representing a matrix. If there are 4 elements, tx and ty are set to 0.
Parameters:
matrix - contains the matrix elements in the following order: a, b, c, d, tx, ty
• Matrix

public Matrix​(double a,
double b,
double c,
double d,
double tx,
double ty)
• Method Detail

• isIdentity

public boolean isIdentity()
Returns true iff this is very close to representing the identity transformation.
• isInverse

public boolean isInverse​(Matrix inverse)
Checks whether 'inverse' is the inverse of this matrix.
Parameters:
inverse - the matrix to be compared
Returns:
true iff this * inverse ~= IDENTITY_MATRIX
• multiply

public Matrix multiply​(Matrix multiplier)
Computes this * multiplier and returns the resulting matrix.
• multiply

public Matrix multiply​(double multiplier)
Computes this * multiplier and returns the resulting matrix.
• applyToPoint

public void applyToPoint​(Point p)
computes p * this and returns the result in p
• applyToXYGetX

public double applyToXYGetX​(double x,
double y)
computes [x y] * this and returns the resulting x value
• applyToXYGetY

public double applyToXYGetY​(double x,
double y)
computes [x y] * this and returns the resulting y value