Main Content

rotvec

Convert quaternion to rotation vector (radians)

Description

example

rotationVector= rotvec(quat)converts the quaternion array,quat, to anN3矩阵of equivalent rotation vectors in radians. The elements ofquatare 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×31.6866 -2.0774 0.7929

Input Arguments

collapse all

Quaternion to convert, specified as scalar quaternion, vector, matrix, or multidimensional array of quaternions.

Data Types:quaternion

Output Arguments

collapse all

Rotation vector representation, returned as anN3矩阵of rotations vectors, where each row represents the [X Y Z] angles of the rotation vectors in radians. Theith row ofrotationVectorcorresponds to the elementquat(i).

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

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 = cos ( θ 2 ) + sin ( θ 2 ) ( xi + y j + z k ) ,

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

Given a quaternion of the form

q = a + b i + c j + d k ,

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

θ = 2 cos 1 ( a ) .

Assuming a normalized axis, you can rewrite the quaternion as a rotation vector without loss of information by distributingθover the partsb,c, andd. The rotation vector representation ofqis

q rv = θ sin ( θ 2 ) [ b , c , d ] .

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

版本sion History

Introduced in R2018b