Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Matrix Structure

Represents a 3x3 affine transformation matrix used for transformations in 2-D space.

Namespace:  System.Windows.Media
Assembly:  WindowsBase (in WindowsBase.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[SerializableAttribute]
[TypeConverterAttribute(typeof(MatrixConverter))]
public struct Matrix : IFormattable
<object property="m11, m12, m21, m22, offsetX, offsetY"/>
- or -
<object property="Identity"/>

XAML Values

m11

System.Double

The value in the first row and first column of this Matrix. For more information, see the M11 property.

m12

System.Double

The value in the first row and second column. For more information, see the M12 property.

m21

System.Double

The value in the second row and first column. For more information, see the M21 property.

m22

System.Double

The value in the second row and second column. For more information, see the M22 property.

offsetX

System.Double

The value in the third row and third column. For more information, see the OffsetX property.

offsetY

System.Double

The value in the third row and second column. For more information, see the OffsetY property.

The Matrix type exposes the following members.

  NameDescription
Public methodMatrix Initializes a new instance of the Matrix structure.
Top
  NameDescription
Public propertyDeterminant Gets the determinant of this Matrix structure.
Public propertyHasInverse Gets a value that indicates whether this Matrix structure is invertible.
Public propertyStatic memberIdentity Gets an identity Matrix.
Public propertyIsIdentity Gets a value that indicates whether this Matrix structure is an identity matrix.
Public propertyM11Gets or sets the value of the first row and first column of this Matrix structure.
Public propertyM12 Gets or sets the value of the first row and second column of this Matrix structure.
Public propertyM21 Gets or sets the value of the second row and first column of this Matrix structure.
Public propertyM22Gets or sets the value of the second row and second column of this Matrix structure.
Public propertyOffsetXGets or sets the value of the third row and first column of this Matrix structure.
Public propertyOffsetYGets or sets the value of the third row and second column of this Matrix structure.
Top
  NameDescription
Public methodAppend Appends the specified Matrix structure to this Matrix structure.
Public methodEquals(Matrix) Determines whether the specified Matrix structure is identical to this instance.
Public methodEquals(Object) Determines whether the specified Object is a Matrix structure that is identical to this Matrix. (Overrides ValueType.Equals(Object).)
Public methodStatic memberEquals(Matrix, Matrix) Determines whether the two specified Matrix structures are identical.
Public methodGetHashCode Returns the hash code for this Matrix structure. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInvert Inverts this Matrix structure.
Public methodStatic memberMultiply Multiplies a Matrix structure by another Matrix structure.
Public methodStatic memberParse Converts a String representation of a matrix into the equivalent Matrix structure.
Public methodPrepend Prepends the specified Matrix structure onto this Matrix structure.
Public methodRotate Applies a rotation of the specified angle about the origin of this Matrix structure.
Public methodRotateAtRotates this matrix about the specified point.
Public methodRotateAtPrependPrepends a rotation of the specified angle at the specified point to this Matrix structure.
Public methodRotatePrepend Prepends a rotation of the specified angle to this Matrix structure.
Public methodScale Appends the specified scale vector to this Matrix structure.
Public methodScaleAtScales this Matrix by the specified amount about the specified point.
Public methodScaleAtPrependPrepends the specified scale about the specified point of this Matrix.
Public methodScalePrepend Prepends the specified scale vector to this Matrix structure.
Public methodSetIdentity Changes this Matrix structure into an identity matrix.
Public methodSkew Appends a skew of the specified degrees in the x and y dimensions to this Matrix structure.
Public methodSkewPrepend Prepends a skew of the specified degrees in the x and y dimensions to this Matrix structure.
Public methodToString() Creates a String representation of this Matrix structure. (Overrides ValueType.ToString().)
Public methodToString(IFormatProvider) Creates a String representation of this Matrix structure with culture-specific formatting information.
Public methodTransform(Point)Transforms the specified point by the Matrix and returns the result.
Public methodTransform(Point[])Transforms the specified points by this Matrix.
Public methodTransform(Vector)Transforms the specified vector by this Matrix.
Public methodTransform(Vector[])Transforms the specified vectors by this Matrix.
Public methodTranslate Appends a translation of the specified offsets to this Matrix structure.
Public methodTranslatePrepend Prepends a translation of the specified offsets to this Matrix structure.
Top
  NameDescription
Public operatorStatic memberEquality Determines whether the two specified Matrix structures are identical.
Public operatorStatic memberInequality Determines whether the two specified Matrix structures are not identical.
Public operatorStatic memberMultiply Multiplies a Matrix structure by another Matrix structure.
Top
  NameDescription
Explicit interface implemetationPrivate methodIFormattable.ToStringFormats the value of the current instance using the specified format.
Top

A 3x3 matrix is used for transformations in a 2-D x-y plane. Affine transformation matrices can be multiplied to form any number of linear transformations, such as rotation and skew (shear), followed by translation. An affine transformation matrix has its final column equal to (0, 0, 1), so only the members in the first two columns need to be specified.  Note that vectors are expressed as row-vectors, not column vectors. 

A WPF Matrix is stored using row-major order and has the following structure:

The members in the last row, OffsetX and OffsetY, represent translation values.

In methods and properties, the transformation matrix is usually specified as a vector with only six members, as follows:

    (M11, M12, M21, M22, OffsetX, OffsetY)

Although you can use a Matrix structure directly to translate individual points, or with a MatrixTransform to transform objects, WPF also provides a set of classes that enable you to transform objects without working directly with matrices: RotateTransform, ScaleTransform, SkewTransform, and TranslateTransform.

This example shows how to use a Matrix to transform Point and Vector objects.

private void transformExamples()
{

     Matrix myMatrix = new Matrix(5, 10, 15, 20, 25, 30);


     // 
     // Transform a point. 
     //            
     Point myPoint = new Point(15,25);

     // pointResult is (475, 680).
     Point pointResult = myMatrix.Transform(myPoint);

     // 
     // Transform an array of points. 
     //            
     Point[] myPointArray = new Point[]
        {new Point(15,25), new Point(30,35)};

     // myPointArray[0] becomes (475, 680). 
     // myPointArray[1] becomes (700, 1030).
     myMatrix.Transform(myPointArray);

     // 
     // Transform a vector. 
     //
     Vector myVector = new Vector(15,25);

     // vectorResult becomes (450, 650).
     Vector vectorResult = myMatrix.Transform(myVector);

     // 
     // Transform an array of vectors. 
     //
     Vector[] myVectorArray = new Vector[]
        {new Vector(15, 25), new Vector(30,35)};

     // myVectorArray[0] becomes (450, 650). 
     // myVectorArray[1] becomes (675, 1000).             
     myMatrix.Transform(myVectorArray);   


}

More Code

How to: Animate a Matrix by Using Key FramesThis example shows how to animate the Matrix property of a MatrixTransform by using key frames.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.