This class encapsulates a 3x3 transformation matrix for use with most
of the graphics elements in the System.Drawing and
nested namespaces.
You can get an array of the Elements in the array
(ordered {1,1},{1,2},{2,1},{2,2},{3,1},{3,2}). {1,3}, {2,3}, {3,3}
are wired to {0,0,1} and hence do not appear in the array. {3,1} and
{3,2} apply a translation and can be retrieved independently through
the OffsetX and OffsetY
properties. You can also determine if the matrix
IsInvertible (you invert it with the aptly named
Invert() method). If the matrix is the identity
matrix {1,0,0},{0,1,0},{0,0,1}, IsIdentity will be
true.
There are then a host of methods that allow you to transform the
matrix. You can Rotate(), Translate(), Scale(), and Shear() the object. You can also Reset() the
matrix back to the identity or Multiply() by
another matrix. Each method can be performed either prepending or
appending the transform: matrix arithmetic is not commutative.
In addition to being able to apply the matrix to a variety of
different graphics structures, you can use the
TransformPoints() and TransformVectors() methods to transform a set of points. The latter does not
apply the offset with the transform.
public sealed class Matrix : MarshalByRefObject : IDisposable {
// Public Constructors
public Matrix();
public Matrix(System.Drawing.RectangleF rect, System.Drawing.PointF[ ] plgpts);
public Matrix(System.Drawing.Rectangle rect, System.Drawing.Point[ ] plgpts);
public Matrix(float m11, float m12, float m21, float m22, float dx, float dy);
// Public Instance Properties
public float[ ] Elements{get; }
public bool IsIdentity{get; }
public bool IsInvertible{get; }
public float OffsetX{get; }
public float OffsetY{get; }
// Public Instance Methods
public Matrix Clone();
public void Dispose(); // implements IDisposable
public override bool Equals(object obj); // overrides object
public override int GetHashCode(); // overrides object
public void Invert();
public void Multiply(Matrix matrix);
public void Multiply(Matrix matrix, MatrixOrder order);
public void Reset();
public void Rotate(float angle);
public void Rotate(float angle, MatrixOrder order);
public void RotateAt(float angle, System.Drawing.PointF point);
public void RotateAt(float angle, System.Drawing.PointF point, MatrixOrder order);
public void Scale(float scaleX, float scaleY);
public void Scale(float scaleX, float scaleY, MatrixOrder order);
public void Shear(float shearX, float shearY);
public void Shear(float shearX, float shearY, MatrixOrder order);
public void TransformPoints(System.Drawing.Point[ ] pts);
public void TransformPoints(System.Drawing.PointF[ ] pts);
public void TransformVectors(System.Drawing.Point[ ] pts);
public void TransformVectors(System.Drawing.PointF[ ] pts);
public void Translate(float offsetX, float offsetY);
public void Translate(float offsetX, float offsetY, MatrixOrder order);
public void VectorTransformPoints(System.Drawing.Point[ ] pts);
// Protected Instance Methods
protected override void Finalize(); // overrides object
}