# tform2rotm

Extract rotation matrix from homogeneous transformation

## Syntax

``rotm = tform2rotm(tform)``

## Description

example

````rotm = tform2rotm(tform)` extracts the rotational component from a homogeneous transformation, `tform`, and returns it as an orthonormal rotation matrix, `rotm`. The translational components of `tform` are ignored. The input homogeneous transformation must be in the pre-multiply form for transformations. When using the rotation matrix, premultiply it with the coordinates to be rotated (as opposed to postmultiplying).```

## Examples

collapse all

```tform = [1 0 0 0; 0 -1 0 0; 0 0 -1 0; 0 0 0 1]; rotm = tform2rotm(tform)```
```rotm = 3×3 1 0 0 0 -1 0 0 0 -1 ```

## Input Arguments

collapse all

Homogeneous transformation, specified as a 3-by-3-by-n array or 4-by-4-by-n array. n is the number of homogeneous transformations. The input homogeneous transformation must be in the premultiplied form for transformations.

2-D homogeneous transformation matrices are of the 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 the 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]`

## Output Arguments

collapse all

Rotation matrix, returned as a 2-by-2-n array or 3-by-3-by-n array containing n rotation matrices. Each rotation matrix in the array has either a size of 2-by-2 or 3-by-3 and is orthonormal. When using the rotation matrix, premultiply it with the coordinates to be rotated (as opposed to postmultiplying).

2-D rotation matrices are of the form:

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

3-D rotation matrices are of the 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]```

collapse all

### Homogeneous Transformation Matrices

Homogeneous transformation matrices consist of both an orthogonal rotation and a translation.

2-D Transformations

2-D transformations have a rotation θ about the z-axis:

`${R}_{z}\left(\theta \right)=\left[\begin{array}{cc}\mathrm{cos}\theta & -\mathrm{sin}\theta \\ \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right]$`

, and a translation along the x and y axis:

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

, resulting in the 2-D transformation matrix of the form:

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

3-D Transformations

3-D transformations contain information about three rotations about the x-, y-, and z-axes:

`${R}_{x}\left(\varphi \right)=\left[\begin{array}{ccc}1& 0& 0\\ 0& \mathrm{cos}\varphi & \mathrm{sin}\varphi \\ 0& -\mathrm{sin}\varphi & \mathrm{cos}\varphi \end{array}\right],{R}_{y}\left(\psi \right)=\left[\begin{array}{ccc}\mathrm{cos}\psi & 0& \mathrm{sin}\psi \\ 0& 1& 0\\ -\mathrm{sin}\psi & 0& \mathrm{cos}\psi \end{array}\right],{R}_{z}\left(\theta \right)=\left[\begin{array}{ccc}\mathrm{cos}\theta & -\mathrm{sin}\theta & 0\\ \mathrm{sin}\theta & \mathrm{cos}\theta & 0\\ 0& 0& 1\end{array}\right]$`

and after multiplying become the rotation about the xyz-axes:

`$\begin{array}{l}{R}_{xyz}={R}_{x}\left(\varphi \right){R}_{y}\left(\psi \right){R}_{z}\left(\theta \right)=\\ \left[\begin{array}{ccc}\mathrm{cos}\varphi \mathrm{cos}\psi \mathrm{cos}\theta -\mathrm{sin}\varphi \mathrm{sin}\theta & -\mathrm{cos}\varphi \mathrm{cos}\psi \mathrm{sin}\theta -\mathrm{sin}\varphi \mathrm{cos}\theta & \mathrm{cos}\varphi \mathrm{sin}\psi \\ \mathrm{sin}\varphi \mathrm{cos}\psi \mathrm{cos}\theta +\mathrm{cos}\varphi \mathrm{sin}\theta & -\mathrm{sin}\varphi \mathrm{cos}\psi \mathrm{sin}\theta +\mathrm{cos}\varphi \mathrm{cos}\theta & \mathrm{sin}\varphi \mathrm{sin}\psi \\ -\mathrm{sin}\psi \mathrm{cos}\theta & \mathrm{sin}\psi \mathrm{sin}\theta & \mathrm{cos}\psi \end{array}\right]\end{array}$`

and a translation along the x-, y-, and z-axis:

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

, resulting in the 3-D transformation matrix of the form:

`$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]·\left[\begin{array}{cc}R& 0\\ {0}_{1x3}& 1\end{array}\right]$`

## Version History

Introduced in R2015a

expand all