#799 – How Transforms Are Combined

Because all transforms in WPF use homogeneous coordinates, combining transforms is accomplished simply by multiplying one or more 3 x 3 matrices together.

For example, suppose that we want to combine a rotation and a translation transform:

                <TransformGroup>
                    <RotateTransform Angle="30"/>
                    <TranslateTransform X="5.0" Y="10.0"/>
                </TransformGroup>

Recall that the 3 x 3 transformation matrix for rotation looks like:
799-001

And recall that the 3 x 3 transformation matrix for translation looks like:

799-002

To combine these two transforms together, we multiply the matrices, but in the opposite order from how they are listed:

799-005

For the example above, that works out to:

799-006

Multiplying any point by this final matrix will result in the point first being rotated and then translated.

In WPF, all of this works automatically behind the scenes.  You just specify in XAML the transforms that you want applied to your user interface elements and WPF calculates and stores the proper transformation matrix.

Advertisements