# rotvec

Convert quaternion to rotation vector (radians)

## Syntax

``rotationVector = rotvec(quat)``

## Description

example

````rotationVector = rotvec(quat)` converts the quaternion array, `quat`, to an N-by-3 matrix of equivalent rotation vectors in radians. The elements of `quat` are normalized before conversion.```

## Examples

collapse all

Convert a random quaternion scalar to a rotation vector in radians

```quat = quaternion(randn(1,4)); rotvec(quat)```
```ans = 1×3 1.6866 -2.0774 0.7929 ```

## Input Arguments

collapse all

Quaternion to convert, specified as a `quaternion` object or an array of `quaternion` objects of any dimensionality.

## Output Arguments

collapse all

Rotation vector representation, in radians, returned as an N-by-3 numeric matrix of rotation vectors, where N is the number of quaternions in the `quat` argument.

Each row represents the [X Y Z] angles of the rotation vectors. The ith row of `rotationVector` corresponds to the element `quat(i)`.

The data type of the rotation vector is the same as the underlying data type of `quat`.

Data Types: `single` | `double`

## Algorithms

All rotations in 3-D can be represented by a three-element axis of rotation and a rotation angle, for a total of four elements. If the rotation axis is constrained to be unit length, the rotation angle can be distributed over the vector elements to reduce the representation to three elements.

Recall that a quaternion can be represented in axis-angle form

`$q=\mathrm{cos}\left(\theta }{2}\right)+\mathrm{sin}\left(\theta }{2}\right)\left(\text{xi}+y\text{j}+z\text{k}\right),$`

where θ is the angle of rotation and [x,y,z] represent the axis of rotation.

Given a quaternion of the form

`$q=a+bi+cj+dk\text{\hspace{0.17em}},$`

you can solve for the rotation angle using the axis-angle form of quaternions:

`$\theta =2{\mathrm{cos}}^{-1}\left(a\right).$`

Assuming a normalized axis, you can rewrite the quaternion as a rotation vector without loss of information by distributing θ over the parts b, c, and d. The rotation vector representation of q is

`${q}_{\text{rv}}=\frac{\theta }{\mathrm{sin}\left(\theta }{2}\right)}\left[b,c,d\right].$`

## Version History

Introduced in R2018a