Matrix Matrix Matrix Struct

Represents a 3 × 3 affine transformation matrix used for transformations in two-dimensional space.

Syntax

Declaration

public struct Matrixpublic struct MatrixPublic Structure Matrix
<Matrix .../>

Remarks

A 3×3 matrix is used for transformations in a two-dimensional 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 Matrix is stored using row-major order and has the following structure:

M11M120
M21M220
OffsetXOffsetY1

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, the Windows Runtime also provides a set of classes that can transform objects without working directly with matrices:

Properties of a Matrix can be animated (as one or more DoubleAnimation animations or DoubleAnimationUsingKeyFrames ).

Matrix is the property value for the Matrix property. Related types can be used for transformation matrices in three-dimensional space and then used for a projection. See Matrix3D and Matrix3DProjection.

Language projections and members of Matrix

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), or in Visual C++ component extensions (C++/CX) then Matrix has non-data members available, and its data members are exposed as read-write properties, not fields.

If you are programming with C++ using the Windows Runtime Template Library (WRL), then only the data member fields exist as members of Matrix, and you cannot use the utility methods or properties listed in the members table. WRL code can access similar utility methods that exist on the MatrixHelper class.

Examples

This example XAML defines a Matrix that provides data for a MatrixTransform applied to a rectangular shape. In this case, the matrix combines an offset (OffsetX and OffsetY ) and a skew (M12 ). Note that this same effect could have been produced by combining a TranslateTransform and a SkewTransform. Whether to use a single Matrix or combinations of discrete transforms is a matter of coding style; the results are identical.

<Rectangle Width="60" Height="60" Fill="Blue">
    <Rectangle.RenderTransform>
        <MatrixTransform>
            <MatrixTransform.Matrix >

                <!-- This matrix transforms the x,y position of
                     the rectangle and skews it. -->
                <Matrix OffsetX="30" OffsetY="100" M12="0.5" />
            </MatrixTransform.Matrix>
        </MatrixTransform>
    </Rectangle.RenderTransform>

</Rectangle>

Fields summary

The value of the first row and first column of this Matrix structure.

The value of the first row and second column of this Matrix structure.

The value of the second row and first column of this Matrix structure.

The value of the second row and second column of this Matrix structure.

Gets or sets the value of the third row and first column of this Matrix structure.

Gets or sets the value of the third row and second column of this Matrix structure.

Fields

  • M11
    M11
    M11
    M11

    The value of the first row and first column of this Matrix structure.

    public field double M11public field double M11Public Field M11
  • M12
    M12
    M12
    M12

    The value of the first row and second column of this Matrix structure.

    public field double M12public field double M12Public Field M12
  • M21
    M21
    M21
    M21

    The value of the second row and first column of this Matrix structure.

    public field double M21public field double M21Public Field M21
  • M22
    M22
    M22
    M22

    The value of the second row and second column of this Matrix structure.

    public field double M22public field double M22Public Field M22
  • OffsetX
    OffsetX
    OffsetX
    OffsetX

    Gets or sets the value of the third row and first column of this Matrix structure.

    public field double OffsetXpublic field double OffsetXPublic Field OffsetX
  • OffsetY
    OffsetY
    OffsetY
    OffsetY

    Gets or sets the value of the third row and second column of this Matrix structure.

    public field double OffsetYpublic field double OffsetYPublic Field OffsetY

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.UI.Xaml.Media.dll