Main Content

rigidtform2d

R2026b

2-D rigid geometric transformation

Since R2022b. Recommended over rigid2d.

    Description

    A rigidtform2d object stores information about a 2-D rigid geometric transformation and enables forward and inverse transformations.

    Creation

    Description

    tform = rigidtform2d creates a rigidtform2d object that performs an identity transformation.

    tform = rigidtform2d(t) creates a rigidtform2d object that performs a rigid transformation consisting only of translation by the specified amount t.

    If you want a transformation that performs only 2-D translation, consider using the transltform2d object.

    tform = rigidtform2d(rotAngle,t) creates a rigidtform2d object that performs a rigid transformation based on the specified angle of rotation about the origin rotAngle, and amount of translation t.

    example

    tform = rigidtform2d(rotMat,t) creates a rigidtform2d object that performs a rigid transformation based on the specified rotation matrix rotMat, and amount of translation t.

    tform = rigidtform2d(rigidMat) creates a rigidtform2d object from a specified 2-D rigid transformation matrix, rigidMat.

    tform = rigidtform2d(tformIn) creates a rigidtform2d object from another geometric transformation object, tformIn, that represents a valid 2-D rigid geometric transformation.

    Input Arguments

    expand all

    Amount of translation, specified as a 2-element numeric vector of the form [tx ty]. These amounts of translation correspond to the values tx and ty in the rigid transformation matrix defined by A.

    This argument sets the Translation property.

    Data Types: double | single

    Rotation angle about the origin, in degrees, specified as a numeric scalar. The rotation angle corresponds to the value r in the transformation matrix defined by the property A, and in the rotation matrix defined by the property R.

    This argument sets the RotationAngle property.

    Data Types: double | single

    Rotation matrix, specified as a 2-by-2 numeric matrix. The matrix must have the form

     rotMat = [cosd(r) -sind(r); sind(r)  cosd(r)]
    where r is the value of the rotation angle about the origin.

    This argument sets the R property.

    Forward 2-D rigid transformation, specified as a 3-by-3 numeric matrix. You can also specify rigidMat as a 2-by-3 numeric matrix. In this case, the object concatenates the row vector [0 0 1] to the end of the matrix, forming a 3-by-3 matrix.

    A valid 2-D rigid transformation A has the form:

    Α=[cosd(r)−sind(r)txsind(r)cosd(r)ty001]

    r is the rotation angle and sets the RotationAngle property. tx and ty are the amount of translation in the x- and y- directions, respectively, and set the Translation property.

    This argument sets the A property.

    Data Types: double | single

    Rigid 2-D geometric transformation, specified as an affinetform2d object, rigidtform2d object, simtform2d object, transltform2d object, or projtform2d object.

    Output Arguments

    expand all

    Rigid 2-D geometric transformation, returned as a rigidtform2d object.

    Properties

    expand all

    Forward 2-D rigid transformation, specified as a 3-by-3 numeric matrix. The default value of A is the identity matrix.

    The matrix A transforms the point (u, v) in the input coordinate space to the point (x, y) in the output coordinate space using the convention:

    [xy1]=Α×[uv1]

    For a rigid transformation, A has the form:

    Α=[cosd(r)−sind(r)txsind(r)cosd(r)ty001]

    where r is the rotation angle and corresponds to the property RotationAngle. tx and ty are the amount of translation in the x- and y- directions, respectively, and correspond to the property Translation.

    Data Types: double | single

    Rotation matrix, specified as a 2-by-2 numeric matrix. The matrix must have the form

     R = [cosd(r) -sind(r); sind(r)  cosd(r)]
    where r is the value of the RotationAngle property.

    Rotation angle about the origin, in degrees, specified as a numeric scalar. The rotation angle corresponds to the value r in the transformation matrix defined by A, and in the rotation matrix defined by R.

    Data Types: double | single

    Amount of translation, specified as a 2-element numeric vector of the form [tx ty]. These amounts of translation correspond to the values tx and ty in the rigid transformation matrix defined by A.

    Data Types: double | single

    This property is read-only.

    Dimensionality of the geometric transformation for both input and output points, returned as the value 2.

    Data Types: double

    Object Functions

    invertInvert geometric transformation
    outputLimitsFind output spatial limits given input spatial limits
    transformPointsForwardApply forward geometric transformation
    transformPointsInverseApply inverse geometric transformation

    Examples

    collapse all

    Specify a rotation angle and an amount of translation.

    theta = 30;
    translation = [10 20.5];

    Create a rigidtform2d object that performs the specified rotation and translation.

    tform = rigidtform2d(theta,translation)
    tform = 
      rigidtform2d with properties:
    
        Dimensionality: 2
         RotationAngle: 30
           Translation: [10 20.5000]
                     R: [2×2 double]
    
                     A: [0.8660   -0.5000   10.0000
                         0.5000    0.8660   20.5000
                              0         0    1.0000]
    
    

    Examine the value of the A property.

    tform.A
    ans = 3×3
    
        0.8660   -0.5000   10.0000
        0.5000    0.8660   20.5000
             0         0    1.0000
    
    

    Tips

    • The rigidtform2d object does not support reflection. To create a geometric transformation that includes reflection, use an affinetform2d object instead. To check for reflection, calculate the determinant of the rotation matrix rotMat or the upper‑left 2-by-2 submatrix of the rigid transformation matrix, rigidMat. A negative determinant indicates that the transformation includes a reflection.

    • You can the apply the rigid transformation saved in the rigidtform2d object to an image by using the imwarp function.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2022b

    expand all