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)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[SerializableAttribute] 
[TypeConverterAttribute(typeof(MatrixConverter))] 
public struct Matrix : IFormattable
/** @attribute SerializableAttribute() */ 
/** @attribute TypeConverterAttribute(System.Windows.Media.MatrixConverter) */ 
public final class Matrix extends ValueType implements IFormattable
<object property="m11, m12, m21, m22, offsetX, offsetY"/>
- or -
<object property="Identity"/>
 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. 

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 Frames

This example shows how to animate the Matrix property of a MatrixTransform by using key frames.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.