Class Matrix
Replaces the GDI+ Matrix.
public class Matrix
- Inheritance
-
Matrix
- Inherited Members
Remarks
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
Matrix()
Initializes a new instance of the Matrix class as the identity matrix.
public Matrix()
Matrix(Matrix)
Makes a copy of the Matrix class.
public Matrix(Matrix origin)
Parameters
origin
MatrixA base matrix for coping
Matrix(Rectangle, Point[])
Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.
public Matrix(Rectangle rect, Point[] plgpts)
Parameters
rect
RectangleA Rectangle structure that represents the rectangle to be transformed.
plgpts
Point[]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(RectangleF, PointF[])
Initializes a new instance of the Matrix class to the geometric transform defined by the specified rectangle and array of points.
public Matrix(RectangleF rect, PointF[] plgpts)
Parameters
rect
RectangleFA RectangleF structure that represents the rectangle to be transformed.
plgpts
PointF[]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(float, float, float, float, float, float)
Initializes a new instance of the Matrix class.
public Matrix(float m11, float m12, float m21, float m22, float m31, float m32)
Parameters
m11
floatm00 M11 Scale X
m12
floatm10 M12 Shear Y
m21
floatm01 M21 Shear X
m22
floatm11 M22 Scale Y
m31
floatm02 M31 Translate X
m32
floatm12 M32 Translate Y
Fields
TypeFlip
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.
public const int TypeFlip = 64
Field Value
TypeGeneralRotation
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
public const int TypeGeneralRotation = 16
Field Value
TypeGeneralScale
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.
public const int TypeGeneralScale = 4
Field Value
TypeGeneralTransform
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.
public const int TypeGeneralTransform = 32
Field Value
TypeIdentity
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.
public const int TypeIdentity = 0
Field Value
TypeMaskRotation
This constant is a bit mask for any of the rotation flag bits.
public const int TypeMaskRotation = 24
Field Value
TypeMaskScale
This constant is a bit mask for any of the scale flag bits.
public const int TypeMaskScale = 6
Field Value
TypeQuadrantRotation
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.
public const int TypeQuadrantRotation = 8
Field Value
TypeTranslation
A translation moves the coordinates by a constant amount in x and y without changing the length or angle of vectors.
public const int TypeTranslation = 1
Field Value
TypeUniformScale
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.
public const int TypeUniformScale = 2
Field Value
Properties
Elements
Gets an array of floating-point values that represents the elements of this Matrix.
public float[] Elements { get; }
Property Value
M11
Gets the matrix element at first row first column. Represents scale along X axis.
public float M11 { get; }
Property Value
M12
Gets the matrix element at first row second column. Represents shear along Y axis.
public float M12 { get; }
Property Value
M21
Gets the matrix element at second row first column. Represents shear along X axis.
public float M21 { get; }
Property Value
M22
Gets the matrix element at second row second column. Represents scale along Y axis.
public float M22 { get; }
Property Value
M31
Gets the matrix element at third row first column. Represents translation along X axis.
public float M31 { get; }
Property Value
M32
Gets the matrix element at third row first column. Represents translation along Y axis.
public float M32 { get; }
Property Value
Methods
Equals(Matrix, Matrix)
Determines whether two matrixes are equal.
public static bool Equals(Matrix a, Matrix b)
Parameters
Returns
- bool
True if matrixes are equal.
Equals(object)
Determines whether the specified object is equal to this instance.
public override bool Equals(object obj)
Parameters
Returns
Exceptions
- NullReferenceException
The
obj
parameter is null.
GetElements()
Gets the copy of matrix elements.
public float[] GetElements()
Returns
- float[]
A matrix elements copy.
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
Multiply(Matrix)
Multiplies this Matrix by the matrix specified in the matrix parameter using (default) Prepend order.
public void Multiply(Matrix tTx)
Parameters
tTx
MatrixThe matrix to multiply with.
Multiply(Matrix, MatrixOrder)
Multiplies this Matrix by the matrix specified in the matrix parameter, and in the order specified in the order parameter.
public void Multiply(Matrix tTx, MatrixOrder order)
Parameters
tTx
MatrixThe tx. The tx. The tx.
order
MatrixOrderThe order. The order. The order.
Reset()
Resets this Matrix to have the elements of the identity matrix.
public void Reset()
Rotate(float)
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.
public void Rotate(float angle)
Parameters
angle
floatThe rotate angle.
Rotate(float, MatrixOrder)
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.
public void Rotate(float angle, MatrixOrder order)
Parameters
angle
floatThe rotate angle.
order
MatrixOrderThe matrix order.
RotateAt(float, PointF)
Applies a clockwise rotation about the specified point to this Matrix in the default (Prepend) order.
public void RotateAt(float angle, PointF point)
Parameters
RotateAt(float, PointF, MatrixOrder)
Applies a clockwise rotation about the specified point to this Matrix in the specified order.
public void RotateAt(float angle, PointF point, MatrixOrder order)
Parameters
angle
floatThe angle.
point
PointFThe point.
order
MatrixOrderThe order.
Scale(float, float)
Applies the specified scale vector (scaleX and scaleY) to this Matrix using (default) Prepend order.
public void Scale(float sx, float sy)
Parameters
Scale(float, float, MatrixOrder)
Applies the specified scale vector (scaleX and scaleY) to this Matrix using the specified order.
public void Scale(float scaleX, float scaleY, MatrixOrder order)
Parameters
scaleX
floatThe scale X.
scaleY
floatThe scale Y.
order
MatrixOrderThe order.
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
TransformPoints(PointF[])
Applies the geometric transform represented by this Matrix to a specified array of points.
public void TransformPoints(PointF[] points)
Parameters
points
PointF[]The points.
Translate(float, float)
Applies the specified translation vector to this Matrix using (default) Prepend order.
public void Translate(float tx, float ty)
Parameters
Translate(float, float, MatrixOrder)
Applies the specified translation vector to this Matrix in the specified order.
public void Translate(float offsetX, float offsetY, MatrixOrder order)
Parameters
offsetX
floatThe offset X.
offsetY
floatThe offset Y.
order
MatrixOrderThe order.