product#
- Quaternion.product(q: ndarray) 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}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 \end{bmatrix} \\ & = & \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:
q (numpy.ndarray, Quaternion) – Quaternion to multiply with.
- Returns:
pq – Product of quaternions.
- Return type:
numpy.ndarray
Examples
>>> p = Quaternion(random=True) >>> p.view() Quaternion([ 0.22091606, 0.94554179, -0.23723731, 0.02941561]) >>> q = Quaternion(random=True) Quaternion([-0.12430979, 0.83988925, -0.39229689, 0.35388736]) >>> p.product(q) array([-0.92508969, -0.0044107 , -0.3670832 , -0.09715728])
It holds with the result after the cross and dot product definition
>>> rw = p.w*q.w - np.dot(p.v, q.v) >>> rv = p.w*q.v + q.w*p.v + np.cross(p.v, q.v) >>> rw, rv (-0.9250896906548645, array([-0.0044107 , -0.3670832 , -0.09715728]))
Can multiply with a normalized quaternion in an array …
>>> p.product([-0.12430979, 0.83988925, -0.39229689, 0.35388736]) array([-0.92508969, -0.0044107 , -0.3670832 , -0.09715728])
but it ALSO MULTIPLIES with non-unitary quaternions (assumed to be simple vectors with 4 elements in them.)
>>> r = np.random.random(4) * 10 >>> r.view() array([8.48031045, 2.49690044, 5.78466679, 6.30034199]) >>> p.product(r) array([ 0.69952346, 6.90525759, -6.61770901, 7.70330242])
The result of this latter operation does NOT yield a unitary quaternion. Thus, the user must normalize the array, if a unitary quaternion is desired.