Main Content

quatrotate

Rotate vector by quaternion

Description

example

n= quatrotate(q,r)calculates the rotated vector,n, for a quaternion,q, and a vector,r. If quaternions are not yet normalized, the function normalizes them.

Aerospace Toolboxuses quaternions that are defined using the scalar-first convention. This function normalizes all quaternion inputs.

Examples

collapse all

This example shows how to rotate a 1-by-3 vector by a 1-by-4 quaternion.

q = [1 0 1 0]; r = [1 1 1]; n = quatrotate(q, r)
n =1×31。0000 1.0000 1.0000

This example shows how to rotate two 1-by-3 vectors by a 1-by-4 quaternion.

q = [1 0 1 0]; r = [1 1 1; 2 3 4]; n = quatrotate(q, r)
n =2×31。0000 1.0000 1.0000 -4.0000 3.0000 2.0000

This example shows how to rotate a 1-by-3 vector by two 1-by-4 quaternions.

q = [1 0 1 0; 1 0.5 0.3 0.1]; r = [1 1 1]; n = quatrotate(q, r)
n =2×31。0000 1.0000 1.0000 0.8519 1.4741 0.3185

This example shows how to rotate multiple vectors by multiple quaternions.

q = [1 0 1 0; 1 0.5 0.3 0.1]; r = [1 1 1; 2 3 4]; n = quatrotate(q, r)
n =2×31。0000 1.0000 1.0000 1.3333 5.1333 0.9333

Input Arguments

collapse all

Quaternion or set of quaternions, specified as anm-by-4 matrix containingmquaternions, or a single 1-by-4 quaternion. Each element must be real.

qmust have its scalar number as the first column.

Data Types:double|single

Vector or set of vectors to be rotated, specified as anm3矩阵, containingmvectors, or a single 1-by-3 array. Each element must be real.

Data Types:double|single

Output Arguments

collapse all

Rotated vector, returned as anm3矩阵.

More About

collapse all

q

Quaternionqhas the form:

q = q 0 + i q 1 + j q 2 + k q 3

r

Vectorrhas the form:

v = i v 1 + j v 2 + k v 3

n

Rotated vectornhas the form:

v = [ v 1 v 2 v 3 ] = [ ( 1 2 q 2 2 2 q 3 2 ) 2 ( q 1 q 2 + q 0 q 3 ) 2 ( q 1 q 3 q 0 q 2 ) 2 ( q 1 q 2 q 0 q 3 ) ( 1 2 q 1 2 2 q 3 2 ) 2 ( q 2 q 3 + q 0 q 1 ) 2 ( q 1 q 3 + q 0 q 2 ) 2 ( q 2 q 3 q 0 q 1 ) ( 1 2 q 1 2 2 q 2 2 ) ] [ v 1 v 2 v 3 ]

The direction cosine matrix for this equation expects a normalized quaternion.

References

[1] Stevens, Brian L., Frank L. Lewis.Aircraft Control and Simulation, 2nd Edition. Hoboken, NJ: John Wiley & Sons, 2003.

[2] Diebel, James. "Representing Attitude: Euler Angles, Unit Quaternions, and Rotation Vectors." Stanford University, Stanford, California, 2006.

Version History

Introduced in R2006b