product

Quaternion.product(q: numpy.ndarray) → numpy.ndarray

Product of two quaternions.

Given two unit quaternions \(\mathbf{p}=(p_w, \mathbf{p}_v)\) and \(\mathbf{q} = (q_w, \mathbf{q}_v)\), their product is defined [Sola] [Dantam] as:

\[\begin{split}\begin{eqnarray} \mathbf{pq} & = & \big( (q_w p_w - \mathbf{q}_v \cdot \mathbf{p}_v) \; , \; \mathbf{q}_v \times \mathbf{p}_v + q_w \mathbf{p}_v + p_w \mathbf{q}_v \big) \\ & = & \begin{bmatrix} p_w & -\mathbf{p}_v^T \\ \mathbf{p}_v & p_w \mathbf{I}_3 + \lfloor \mathbf{p}_v \rfloor_\times \end{bmatrix} \begin{bmatrix} q_w \\ \mathbf{q}_v \end{bmatrix} \\ & = & \begin{bmatrix} p_w & -p_x & -p_y & -p_z \\ p_x & p_w & -p_z & p_y \\ p_y & p_z & p_w & -p_x \\ p_z & -p_y & p_x & p_w \end{bmatrix} \begin{bmatrix} q_w \\ q_x \\ q_y \\ q_z \end{bmatrix} \\ & = & \begin{bmatrix} p_w q_w - p_x q_x - p_y q_y - p_z q_z \\ p_w q_x + p_x q_w + p_y q_z - p_z q_y \\ p_w q_y - p_x q_z + p_y q_w + p_z q_x \\ p_w q_z + p_x q_y - p_y q_x + p_z q_w \end{bmatrix} \end{eqnarray}\end{split}\]

where \(\lfloor \mathbf{a} \rfloor_\times\) represents the skew-symmetric matrix of \(\mathbf{a}\).

Parameters:r (numpy.ndarray, Quaternion) – Quaternion to multiply with.
Returns:qr – Product of quaternions.
Return type:numpy.ndarray

Examples

>>> q1 = Quaternion([0.55747131, 0.12956903, 0.5736954 , 0.58592763])

Can multiply with a given quaternion in vector form…

>>> q1.product([0.49753507, 0.50806522, 0.52711628, 0.4652709])
array([-0.36348726,  0.38962514,  0.34188103,  0.77407146])

or with a Quaternion object…

>>> q2 = Quaternion([0.49753507, 0.50806522, 0.52711628, 0.4652709 ])
>>> q1.product(q2)
array([-0.36348726,  0.38962514,  0.34188103,  0.77407146])

It holds with the result after the cross and dot product definition

>>> qw = q1.w*q2.w - np.dot(q1.v, q2.v)
>>> qv = q1.w*q2.v + q2.w*q1.v + np.cross(q1.v, q2.v)
>>> qw, qv
(-0.36348726, array([0.38962514,  0.34188103,  0.77407146]))