# #799 – How Transforms Are Combined

April 16, 2013 1 Comment

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:

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

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

For the example above, that works out to:

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.

Pingback: Dew Drop – April 16, 2013 (#1,528) | Alvin Ashcraft's Morning Dew