Matrix

Inheritance: java.lang.Object

public class Matrix

Replaces the GDI+ Matrix.


Most algorithms taken from Sun’s AffineTransform.java. Java’s names for matrix elements used internally. Map of java names to .net ones to description: m00 M11 Scale X m10 M12 Shear Y m01 M21 Shear X m11 M22 Scale Y m02 M31 Translate X m12 M32 Translate Y

Constructors

ConstructorDescription
Matrix()Initializes a new instance of the Matrix class as the identity matrix.
Matrix(float m11, float m12, float m21, float m22, float m31, float m32)Initializes a new instance of the Matrix class.
Matrix(RectangleF rect, PointF[] plgpts)Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.
Matrix(Rectangle rect, Point[] plgpts)Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.
Matrix(Matrix origin)Makes a copy of the Matrix class.

Fields

FieldDescription
TYPE_IDENTITYAn identity transform is one in which the output coordinates are always the same as the input coordinates.
TYPE_TRANSLATIONA translation moves the coordinates by a constant amount in x and y without changing the length or angle of vectors.
TYPE_UNIFORM_SCALEA uniform scale multiplies the length of vectors by the same amount in both the x and y directions without changing the angle between vectors.
TYPE_GENERAL_SCALEA general scale multiplies the length of vectors by different amounts in the x and y directions without changing the angle between perpendicular vectors.
TYPE_MASK_SCALEThis constant is a bit mask for any of the scale flag bits.
TYPE_FLIPThis flag bit indicates that the transform defined by this object performs a mirror image flip about some axis which changes the normally right handed coordinate system into a left handed system in addition to the conversions indicated by other flag bits.
TYPE_QUADRANT_ROTATIONThis flag bit indicates that the transform defined by this object performs a quadrant rotation by some multiple of 90 degrees in addition to the conversions indicated by other flag bits.
TYPE_GENERAL_ROTATIONThis flag bit indicates that the transform defined by this object performs a rotation by an arbitrary angle in addition to the conversions indicated by other flag bits.
TYPE_MASK_ROTATIONThis constant is a bit mask for any of the rotation flag bits.
TYPE_GENERAL_TRANSFORMThis constant indicates that the transform defined by this object performs an arbitrary conversion of the input coordinates.

Methods

MethodDescription
isEquals(Matrix a, Matrix b)Determines whether two matrices are equal.
getM11()Gets the matrix element at first row first column.
getM12()Gets the matrix element at first row second column.
getM21()Gets the matrix element at second row first column.
getM22()Gets the matrix element at second row second column.
getM31()Gets the matrix element at third row first column.
getM32()Gets the matrix element at third row first column.
toString()Returns a String that represents this instance.
getElements()Gets the copy of matrix elements.
transformPoints(PointF[] points)Applies the geometric transform represented by this Matrix to a specified array of points.
scale(float scaleX, float scaleY, int order)Applies the specified scale vector (scaleX and scaleY) to this Matrix using the specified order.
scale(float sx, float sy)Applies the specified scale vector (scaleX and scaleY) to this Matrix using (default) Prepend order.
translate(float offsetX, float offsetY, int order)Applies the specified translation vector to this Matrix in the specified order.
translate(float tx, float ty)Applies the specified translation vector to this Matrix using (default) Prepend order.
multiply(Matrix tTx, int order)Multiplies this Matrix by the matrix specified in the matrix parameter, and in the order specified in the order parameter.
multiply(Matrix tTx)Multiplies this Matrix by the matrix specified in the matrix parameter using (default) Prepend order.
rotate(float angle, int order)Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix in the specified order.
rotate(float angle)Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix in the default (Prepend) order.
rotateAt(float angle, PointF point, int order)Applies a clockwise rotation about the specified point to this Matrix in the specified order.
rotateAt(float angle, PointF point)Applies a clockwise rotation about the specified point to this Matrix in the default (Prepend) order.
reset()Resets this Matrix to have the elements of the identity matrix.
hashCode()Returns a hash code for this instance.
equals(Object obj)Determines whether the specified Object is equal to this instance.
isIdentity()Returns true if this AffineTransform is an identity transform.

Matrix()

public Matrix()

Initializes a new instance of the Matrix class as the identity matrix.

Matrix(float m11, float m12, float m21, float m22, float m31, float m32)

public Matrix(float m11, float m12, float m21, float m22, float m31, float m32)

Initializes a new instance of the Matrix class.

Parameters:

ParameterTypeDescription
m11floatm00 M11 Scale X
m12floatm10 M12 Shear Y
m21floatm01 M21 Shear X
m22floatm11 M22 Scale Y
m31floatm02 M31 Translate X
m32floatm12 M32 Translate Y

Matrix(RectangleF rect, PointF[] plgpts)

public Matrix(RectangleF rect, PointF[] plgpts)

Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.

Parameters:

ParameterTypeDescription
rectRectangleFA RectangleF structure that represents the rectangle to be transformed.
plgptsPointF[]An array of three PointF structures that represents the points of a parallelogram to which the upper-left, upper-right, and lower-left corners of the rectangle is to be transformed. The lower-right corner of the parallelogram is implied by the first three corners.

Matrix(Rectangle rect, Point[] plgpts)

public Matrix(Rectangle rect, Point[] plgpts)

Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.

Parameters:

ParameterTypeDescription
rectRectangleA Rectangle structure that represents the rectangle to be transformed.
plgptsPoint[]An array of three Point structures that represents the points of a parallelogram to which the upper-left, upper-right, and lower-left corners of the rectangle is to be transformed. The lower-right corner of the parallelogram is implied by the first three corners.

Matrix(Matrix origin)

public Matrix(Matrix origin)

Makes a copy of the Matrix class.

Parameters:

ParameterTypeDescription
originMatrixA base matrix for coping

TYPE_IDENTITY

public static final int TYPE_IDENTITY

An identity transform is one in which the output coordinates are always the same as the input coordinates. If this transform is anything other than the identity transform, the type will either be the constant GENERAL_TRANSFORM or a combination of the appropriate flag bits for the various coordinate conversions that this transform performs.

TYPE_TRANSLATION

public static final int TYPE_TRANSLATION

A translation moves the coordinates by a constant amount in x and y without changing the length or angle of vectors.

TYPE_UNIFORM_SCALE

public static final int TYPE_UNIFORM_SCALE

A uniform scale multiplies the length of vectors by the same amount in both the x and y directions without changing the angle between vectors. This flag bit is mutually exclusive with the TypeGeneralScale flag.

TYPE_GENERAL_SCALE

public static final int TYPE_GENERAL_SCALE

A general scale multiplies the length of vectors by different amounts in the x and y directions without changing the angle between perpendicular vectors. This flag bit is mutually exclusive with the TypeUniformScale flag.

TYPE_MASK_SCALE

public static final int TYPE_MASK_SCALE

This constant is a bit mask for any of the scale flag bits.

TYPE_FLIP

public static final int TYPE_FLIP

This flag bit indicates that the transform defined by this object performs a mirror image flip about some axis which changes the normally right handed coordinate system into a left handed system in addition to the conversions indicated by other flag bits. A right handed coordinate system is one where the positive X axis rotates counterclockwise to overlay the positive Y axis similar to the direction that the fingers on your right hand curl when you stare end on at your thumb. A left handed coordinate system is one where the positive X axis rotates clockwise to overlay the positive Y axis similar to the direction that the fingers on your left hand curl. There is no mathematical way to determine the angle of the original flipping or mirroring transformation since all angles of flip are identical given an appropriate adjusting rotation. NOTE: TypeFlip was added after GENERAL_TRANSFORM was in public circulation and the flag bits could no longer be conveniently renumbered without introducing binary incompatibility in outside code.

TYPE_QUADRANT_ROTATION

public static final int TYPE_QUADRANT_ROTATION

This flag bit indicates that the transform defined by this object performs a quadrant rotation by some multiple of 90 degrees in addition to the conversions indicated by other flag bits. A rotation changes the angles of vectors by the same amount regardless of the original direction of the vector and without changing the length of the vector. This flag bit is mutually exclusive with the TypeGeneralRotation flag.

TYPE_GENERAL_ROTATION

public static final int TYPE_GENERAL_ROTATION

This flag bit indicates that the transform defined by this object performs a rotation by an arbitrary angle in addition to the conversions indicated by other flag bits. A rotation changes the angles of vectors by the same amount regardless of the original direction of the vector and without changing the length of the vector. This flag bit is mutually exclusive with the

TYPE_MASK_ROTATION

public static final int TYPE_MASK_ROTATION

This constant is a bit mask for any of the rotation flag bits.

TYPE_GENERAL_TRANSFORM

public static final int TYPE_GENERAL_TRANSFORM

This constant indicates that the transform defined by this object performs an arbitrary conversion of the input coordinates. If this transform can be classified by any of the above constants, the type will either be the constant TypeIdentity or a combination of the appropriate flag bits for the various coordinate conversions that this transform performs.

isEquals(Matrix a, Matrix b)

public static boolean isEquals(Matrix a, Matrix b)

Determines whether two matrices are equal.

Parameters:

ParameterTypeDescription
aMatrixThe first matrix to compare.
bMatrixThe second matrix to compare.

Returns: boolean - True if matrices are equal.

getM11()

public final float getM11()

Gets the matrix element at first row first column. Represents scale along X axis.

Returns: float - the matrix element at first row first column.

getM12()

public final float getM12()

Gets the matrix element at first row second column. Represents shear along Y axis.

Returns: float - the matrix element at first row second column.

getM21()

public final float getM21()

Gets the matrix element at second row first column. Represents shear along X axis.

Returns: float - the matrix element at second row first column.

getM22()

public final float getM22()

Gets the matrix element at second row second column. Represents scale along Y axis.

Returns: float - the matrix element at second row second column.

getM31()

public final float getM31()

Gets the matrix element at third row first column. Represents translation along X axis.

Returns: float - the matrix element at third row first column.

getM32()

public final float getM32()

Gets the matrix element at third row first column. Represents translation along Y axis.

Returns: float - the matrix element at third row first column.

toString()

public String toString()

Returns a String that represents this instance.

Returns: java.lang.String - A String that represents this instance.

getElements()

public final float[] getElements()

Gets the copy of matrix elements.

Returns: float[] - A matrix elements copy.

transformPoints(PointF[] points)

public final void transformPoints(PointF[] points)

Applies the geometric transform represented by this Matrix to a specified array of points.

Parameters:

ParameterTypeDescription
pointsPointF[]The points.

scale(float scaleX, float scaleY, int order)

public final void scale(float scaleX, float scaleY, int order)

Applies the specified scale vector (scaleX and scaleY) to this Matrix using the specified order.

Parameters:

ParameterTypeDescription
scaleXfloatThe scale X.
scaleYfloatThe scale Y.
orderintThe order.

scale(float sx, float sy)

public final void scale(float sx, float sy)

Applies the specified scale vector (scaleX and scaleY) to this Matrix using (default) Prepend order.

Parameters:

ParameterTypeDescription
sxfloatThe sx. The sx. The sx.
syfloatThe sy. The sy. The sy.

translate(float offsetX, float offsetY, int order)

public final void translate(float offsetX, float offsetY, int order)

Applies the specified translation vector to this Matrix in the specified order.

Parameters:

ParameterTypeDescription
offsetXfloatThe offset X.
offsetYfloatThe offset Y.
orderintThe order.

translate(float tx, float ty)

public final void translate(float tx, float ty)

Applies the specified translation vector to this Matrix using (default) Prepend order.

Parameters:

ParameterTypeDescription
txfloatThe tx. The tx. The tx.
tyfloatThe ty. The ty. The ty.

multiply(Matrix tTx, int order)

public final void multiply(Matrix tTx, int order)

Multiplies this Matrix by the matrix specified in the matrix parameter, and in the order specified in the order parameter.

Parameters:

ParameterTypeDescription
tTxMatrixThe tx. The tx. The tx.
orderintThe order. The order. The order.

multiply(Matrix tTx)

public final void multiply(Matrix tTx)

Multiplies this Matrix by the matrix specified in the matrix parameter using (default) Prepend order.

Parameters:

ParameterTypeDescription
tTxMatrixThe matrix to multiply with.

rotate(float angle, int order)

public final void rotate(float angle, int order)

Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix in the specified order.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle.
orderintThe matrix order.

rotate(float angle)

public final void rotate(float angle)

Applies a clockwise rotation of an amount specified in the angle parameter, around the origin (zero x and y coordinates) for this Matrix in the default (Prepend) order.

Parameters:

ParameterTypeDescription
anglefloatThe rotate angle.

rotateAt(float angle, PointF point, int order)

public final void rotateAt(float angle, PointF point, int order)

Applies a clockwise rotation about the specified point to this Matrix in the specified order.

Parameters:

ParameterTypeDescription
anglefloatThe angle.
pointPointFThe point.
orderintThe order.

rotateAt(float angle, PointF point)

public final void rotateAt(float angle, PointF point)

Applies a clockwise rotation about the specified point to this Matrix in the default (Prepend) order.

Parameters:

ParameterTypeDescription
anglefloatThe angle.
pointPointFThe point.

reset()

public final void reset()

Resets this Matrix to have the elements of the identity matrix.

hashCode()

public int hashCode()

Returns a hash code for this instance.

Returns: int - A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

equals(Object obj)

public boolean equals(Object obj)

Determines whether the specified Object is equal to this instance.

Parameters:

ParameterTypeDescription
objjava.lang.ObjectThe Object to compare with this instance.

Returns: boolean - true if the specified Object is equal to this instance; otherwise, false.

isIdentity()

public boolean isIdentity()

Returns true if this AffineTransform is an identity transform.

Returns: boolean - true if this AffineTransform is an identity transform; false otherwise.