jaxtransform3d.rotations.apply_quaternion#
- jaxtransform3d.rotations.apply_quaternion(q: Array | ndarray | bool_ | number | bool | int | float | complex, v: Array | ndarray | bool_ | number | bool | int | float | complex) Array [source]#
Apply rotation represented by a quaternion to a vector.
We use Hamilton’s quaternion multiplication.
To apply the rotation defined by a unit quaternion \(\boldsymbol{q} \in S^3\) to a vector \(\boldsymbol{v} \in \mathbb{R}^3\), we first represent the vector as a quaternion: we set the scalar part to 0 and the vector part is exactly the original vector \(\left(\begin{array}{c}0\\\boldsymbol{v}\end{array}\right) \in \mathbb{R}^4\). Then we left-multiply the quaternion and right-multiply its conjugate
\[\begin{split}\left(\begin{array}{c}0\\\boldsymbol{w}\end{array}\right) = \boldsymbol{q} \cdot \left(\begin{array}{c}0\\\boldsymbol{v}\end{array}\right) \cdot \boldsymbol{q}^*.\end{split}\]The vector part \(\boldsymbol{w}\) of the resulting quaternion is the rotated vector.
- Parameters:
- qarray-like, shape (…, 4)
Unit quaternion to represent rotation: (w, x, y, z)
- varray-like, shape (…, 3)
3d vector
- Returns:
- warray, shape (…, 3)
3d vector
See also
apply_matrix
Apply rotation matrix to vector.
Examples
>>> import jax.numpy as jnp >>> from jaxtransform3d.rotations import apply_quaternion >>> apply_quaternion(jnp.array([0., 1., 0., 0.]), jnp.array([1., 2., 3.])) Array([ 1., -2., -3.], dtype=...)