Main Content

Migrate Geometric Transformations to Premultiply Convention

Starting in R2022b, functions that create and perform geometric transformations use a premultiply matrix convention.

A new set of objects enable geometric transformations using a premultiply convention. There are no plans to remove the old geometric transformation objects that support a postmultiply convention.

About the Premultiply and Postmultiply Conventions

Using the previous 2-D postmultiply matrix convention, you transform the point (u,v) in the input coordinate space to the point (x,y) in the output coordinate space using the convention:

[xy1]=[uv1]Τ

The geometric transformation matrix T is represented by a 3-by-3 matrix:

Τ=[ad0be0cf1]

In the 2-D premultiply matrix convention, you transform the point (u,v) in the input coordinate space to the point (x,y) in the output coordinate space using the convention:

[xy1]=Α×[uv1]

The geometric transformation matrix A is represented by a 3-by-3 matrix that is the transpose of matrix T:

Α=[abcdef001]

Create New Geometric Transformation Objects from Previous Geometric Transformation Objects

If your code uses one of the previous geometric transformation objects, then you can update your code by using a new geometric transformation object that supports the premultiply convention.

  1. Select a type of new geometric transformation object that performs your desired transformation. The affine and rigid postmultiply geometric transformation objects support multiple types of new premultiply geometric transformation objects. The table shows the available geometric transformations objects that you can use instead of the previous objects.

    Previous Geometric Transformation ObjectCurrent Geometric Transformation Object
    affine2dUse affinetform2d instead. To create a 2-D affine transformation that represents a purely rigid, similar, or translation transformation, use rigidtform2d, simtform2d, or transltform2d, respectively.
    affine3dUse affinetform3d instead. To create a 3-D affine transformation that represents a purely rigid, similar, or translation transformation, use rigidtform3d, simtform3d, or transltform3d, respectively.
    rigid2dUse rigidtform2d instead. To create a 2-D rigid transformation that represents pure translation, use transltform2d.
    rigid3dUse rigidtform3d instead. To create a 3-D rigid transformation that represents pure translation, use transltform3d.
    projective2dUse projtform2d instead.
  2. Create the object using the transpose of the transformation matrix stored in the old object. For example, this code shows how to convert a 2-D affine transformation represented by an affine2d object named tformPost to an affinetform2d object named tformPre.

    T = tformPost.T;
    A = T';
    tformPre = affinetform2d(A);

Related Topics