Main Content

mtimes, *

Quaternion multiplication

Description

quatC = A*B implements quaternion multiplication if either A or B is a quaternion. Either A or B must be a scalar.

You can use quaternion multiplication to compose rotation operators:

  • To compose a sequence of frame rotations, multiply the quaternions in the order of the desired sequence of rotations. For example, to apply a p quaternion followed by a q quaternion, multiply in the order pq. The rotation operator becomes (pq)v(pq), where v represents the object to rotate specified in quaternion form. * represents conjugation.

  • To compose a sequence of point rotations, multiply the quaternions in the reverse order of the desired sequence of rotations. For example, to apply a p quaternion followed by a q quaternion, multiply in the reverse order, qp. The rotation operator becomes (qp)v(qp).

example

Examples

collapse all

Create a 4-by-1 column vector, A, and a scalar, b. Multiply A times b.

A = quaternion(randn(4,4))
A = 4x1 quaternion array
      0.53767 +  0.31877i +   3.5784j +   0.7254k
       1.8339 -   1.3077i +   2.7694j - 0.063055k
      -2.2588 -  0.43359i -   1.3499j +  0.71474k
      0.86217 +  0.34262i +   3.0349j -  0.20497k

b = quaternion(randn(1,4))
b = quaternion
    -0.12414 +  1.4897i +   1.409j +  1.4172k

C = A*b
C = 4x1 quaternion array
      -6.6117 +   4.8105i +  0.94224j -   4.2097k
      -2.0925 +   6.9079i +   3.9995j -   3.3614k
       1.8155 -   6.2313i -    1.336j -     1.89k
      -4.6033 +   5.8317i + 0.047161j -    2.791k

Input Arguments

collapse all

Input to multiply, specified as a quaternion object, an array of quaternion objects of any dimensionality, a real scalar, or an array of real numbers of any dimensionality. Numeric values must be of data type single or double.

If B is nonscalar, then A must be scalar.

Input to multiply, specified as a quaternion object, an array of quaternion objects of any dimensionality, a real scalar, or an array of real numbers of any dimensionality. Numeric values must be of data type single or double.

If A is nonscalar, then B must be scalar.

Output Arguments

collapse all

Quaternion product, returned as a quaternion object or an array of quaternion objects.

Algorithms

collapse all

Quaternion Multiplication by a Real Scalar

Given a quaternion

q=aq+bqi+cqj+dqk,

the product of q and a real scalar β is

βq=βaq+βbqi+βcqj+βdqk

Quaternion Multiplication by a Quaternion Scalar

The definition of the basis elements for quaternions,

i2=j2=k2=ijk=-1,

can be expanded to populate a table summarizing quaternion basis element multiplication:

 1ijk
11ijk
ii−1k−j
jj−k−1i
kkj−i−1

When reading the table, the rows are read first, for example: ij = k and ji = −k.

Given two quaternions, q=aq+bqi+cqj+dqk, and p=ap+bpi+cpj+dpk, the multiplication can be expanded as:

z=pq=(ap+bpi+cpj+dpk)(aq+bqi+cqj+dqk)=apaq+apbqi+apcqj+apdqk+bpaqi+bpbqi2+bpcqij+bpdqik+cpaqj+cpbqji+cpcqj2+cpdqjk+dpaqk+dpbqki+dpcqkj+dpdqk2

You can simplify the equation using the quaternion multiplication table:

z=pq=apaq+apbqi+apcqj+apdqk+bpaqibpbq+bpcqkbpdqj+cpaqjcpbqkcpcq+cpdqi+dpaqk+dpbqjdpcqidpdq

References

[1] Kuipers, Jack B. Quaternions and Rotation Sequences: A Primer with Applications to Orbits, Aerospace, and Virtual Reality. Princeton, NJ: Princeton University Press, 2007.

Extended Capabilities

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

Version History

Introduced in R2018a

See Also

Functions

Objects