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.

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×3

   -1.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×3

   -1.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×3

   -1.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×3

   -1.0000    1.0000    1.0000
    1.3333    5.1333    0.9333

Input Arguments

collapse all

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

q must have its scalar number as the first column.

Data Types: double | single

Vector or set of vectors to be rotated, specified as an m-by-3 matrix, containing m vectors, or a single 1-by-3 array. Each element must be real.

Data Types: double | single

Output Arguments

collapse all

Rotated vector, returned as an m-by-3 matrix.

More About

collapse all

q

Quaternion q has the form:

q=q0+iq1+jq2+kq3

r

Vector r has the form:

v=iv1+jv2+kv3

n

Rotated vector n has the form:

v=[v1v2v3]=[(12q222q32)2(q1q2+q0q3)2(q1q3q0q2)2(q1q2q0q3)(12q122q32)2(q2q3+q0q1)2(q1q3+q0q2)2(q2q3q0q1)(12q122q22)][v1v2v3]

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.

Introduced in R2006b