# rotationMatrixToVector

(Not recommended) Convert 3-D rotation matrix to rotation vector

`rotationMatrixToVector` is not recommended. Use the `rotmat2vec3d` function instead. For more information, see Compatibility Considerations.

## Syntax

``rotationVector = rotationMatrixToVector(rotationMatrix)``

## Description

example

````rotationVector = rotationMatrixToVector(rotationMatrix)` returns an axis-angle rotation vector that corresponds to the input 3-D rotation matrix. The function uses the Rodrigues formula for the conversion.```

## Examples

collapse all

Create a matrix representing a 90-degree rotation about the Z -axis.

`rotationMatrix = [0 1 0; -1 0 0; 0 0 1];`

Find the equivalent rotation vector.

`rotationVector = rotationMatrixToVector(rotationMatrix)`
```rotationVector = 1×3 0 0 1.5708 ```

## Input Arguments

collapse all

Rotation of camera, specified as a 3-by-3 matrix. You can obtain this matrix by using the `estimateExtrinsics` function.

## Output Arguments

collapse all

Rotation vector, returned as a three-element vector. The vector represents the axis of rotation in 3-D, where the magnitude corresponds to the rotation angle in radians.

Data Types: `single` | `double`

## References

[1] Trucco, Emanuele, and Alessandro Verri. Introductory Techniques for 3-D Computer Vision. Upper Saddle River, NJ: Prentice Hall, 1998.

## Version History

Introduced in R2016a

collapse all

### R2022b: Not recommended

Starting in R2022b, most Computer Vision Toolbox™ functions create and perform geometric transformations using the premultiply convention. However, the `rotationMatrixToVector` function uses the postmultiply convention. Although there are no plans to remove `rotationMatrixToVector` at this time, you can streamline your geometric transformation workflows by switching to the `rotmat2vec3d` function, which supports the premultiply convention. For more information, see Migrate Geometric Transformations to Premultiply Convention.

• Change instances of the function name `rotationMatrixToVector` to `rotmat2vec3d`.

• Specify the rotation matrix as the transpose of the `rotationMatrix` argument of the `rotationMatrixToVector` function. Alternatively, you can get a rotation matrix in the correct premultiply format by using the `estimateExtrinsics` function and querying the `R` property of the returned `rigidtform3d` object.

The table shows examples of how to update your code.

Discouraged UsageRecommended Replacement

This example converts a 3-D rotation matrix in the postmultiply convention to a rotation vector using the `rotationMatrixToVector` function.

`rotVectorOld = rotationMatrixToVector(rotMatrixOld)`

This example converts a 3-D rotation matrix in the premultiply convention to a rotation vector using the `rotmat2vec2d` function. The 3-D rotation matrix is the transpose of `rotMatrixOld`.

```rotMatrixNew = rotMatrixOld'; rotVectorNew = rotmat2vec2d(rotMatrixNew);```

This example obtains a 3-D rotation matrix in the postmultiply convention using the `extrinsics` function, then converts the matrix to a rotation vector using the `rotationMatrixToVector` function.

```[rotMatrixOld,transVector] = extrinsics( ... imagePoints,worldPoints,intrinsics); rotVectorOld = rotationMatrixToVector(rotMatrixOld);```

This example obtains a 3-D rotation matrix in the premultiply convention using the `estimateExtrinsics` function, then converts the matrix to a rotation vector using the `rotmat2vec2d` function.

```camExtrinsics = estimateExtrinsics( ... imagePoints,worldPoints,intrinsics); rotMatrixNew = camExtrinsics.R; rotVectorNew = rotmat2vec2d(rotMatrixNew);```