# rotm2tform

Convert rotation matrix to homogeneous transformation

## Syntax

## Description

converts the rotation matrix `tform`

= rotm2tform(`rotm`

)`rotm`

into a homogeneous
transformation matrix `tform`

. The input rotation matrix must be
in the premultiply form for rotations. When using the transformation matrix,
premultiply it by the coordinates to be transformed (as opposed to
postmultiplying).

## Examples

### Convert Rotation Matrix to Homogeneous Transformation

rotm = [1 0 0 ; 0 -1 0; 0 0 -1]; tform = rotm2tform(rotm)

`tform = `*4×4*
1 0 0 0
0 -1 0 0
0 0 -1 0
0 0 0 1

## Input Arguments

`rotm`

— Rotation matrix

2-by-2-by-*n* array | 3-by-3-by-*n* array

Rotation matrix, specified as a 2-by-2-by-*n* or a
3-by-3-by-*n* array containing *n*
rotation matrices. Each rotation matrix is either 2-by-2 or 3-by-3 and is
orthonormal. The input rotation matrix must be in the premultiplied form for
rotations.

**Note**

Rotation matrices that are not orthonormal can be normalized with the
`normalize`

function.

2-D rotation matrices are of this form:

$$R=\left[\begin{array}{cc}{r}_{11}& {r}_{12}\\ {r}_{21}& {r}_{22}\end{array}\right]$$

3-D rotation matrices are of this form:

$$R=\left[\begin{array}{ccc}{r}_{11}& {r}_{12}& {r}_{13}\\ {r}_{11}& {r}_{22}& {r}_{23}\\ {r}_{31}& {r}_{32}& {r}_{33}\end{array}\right]$$

**Example: **`[0 0 1; 0 1 0; -1 0 0]`

## Output Arguments

`tform`

— Homogeneous transformation

3-by-3-by-*n* array | 4-by-4-by-*n* array

Homogeneous transformation, returned as a 3-by-3-by-*n* array or
4-by-4-by-*n* array. *n* is the number of
homogeneous transformations. When using the transformation matrix, premultiply it by the
coordinates to be transformed (as opposed to postmultiplying).

2-D homogeneous transformation matrices are of this form:

$$T=\left[\begin{array}{ccc}{r}_{11}& {r}_{12}& {t}_{1}\\ {r}_{21}& {r}_{22}& {t}_{2}\\ 0& 0& 1\end{array}\right]$$

3-D homogeneous transformation matrices are of this form:

$$T=\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& {t}_{1}\\ {r}_{21}& {r}_{22}& {r}_{23}& {t}_{2}\\ {r}_{31}& {r}_{32}& {r}_{33}& {t}_{3}\\ 0& 0& 0& 1\end{array}\right]$$

**Example: **`[0 0 1 0; 0 1 0 0; -1 0 0 0; 0 0 0 1]`

## More About

### 2-D Homogeneous Transformation Matrix

2-D homogeneous transformation matrices consist of both an SO(2) rotation and an *xy*-translation.

To read more about SO(2) rotations, see the 2-D Orthonormal Rotation Matrix section of the `so2`

object.

The translation is along the *x*-, and *y*-axes as a
two-element column vector:

$$t=\left[\begin{array}{c}x\\ y\end{array}\right]$$

The SO(2) rotation matrix *R* is applied to the
translation vector *t* to create the homogeneous translation matrix
*T*. The rotation matrix is present in the upper-left of the
transformation matrix as 2-by-2 submatrix, and the translation vector is present as a
two-element vector in the last column.

$$T=\left[\begin{array}{cc}R& t\\ {0}_{1\times 2}& 1\end{array}\right]=\left[\begin{array}{cc}{I}_{2}& t\\ {0}_{1\times 2}& 1\end{array}\right]\xb7\left[\begin{array}{cc}R& 0\\ {0}_{1\times 2}& 1\end{array}\right]$$

### 3-D Homogeneous Transformation Matrix

3-D homogeneous transformation matrices consist of both an SO(3) rotation and an *xyz*-translation.

To read more about SO(3) rotations, see the 3-D Orthonormal Rotation Matrix section of the `so3`

object.

The translation is along the *x*-, *y*-, and *z*-axes as a three-element column vector:

$$t=\left[\begin{array}{c}x\\ y\\ z\end{array}\right]$$

The SO(3) rotation matrix *R* is applied to the translation vector *t* to create the homogeneous translation matrix *T*. The rotation matrix is present in the upper-left of the transformation matrix as 3-by-3 submatrix, and the translation vector is present as a three-element vector in the last column.

$$T=\left[\begin{array}{cc}R& t\\ {0}_{1x3}& 1\end{array}\right]=\left[\begin{array}{cc}{I}_{3}& t\\ {0}_{1x3}& 1\end{array}\right]\xb7\left[\begin{array}{cc}R& 0\\ {0}_{1x3}& 1\end{array}\right]$$

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

## Version History

**Introduced in R2015a**

### R2023a: `rotm2tform`

Supports 2-D Rotation Matrices

The `rotm`

argument now accepts 2-D rotation matrices as a
2-by-2-by-*n* array and `rotm2tform`

outputs 2-D transformation matrices as a 3-by-3-by-*n*
array.

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)