rotate_by#

ahrs.common.quaternion.QuaternionArray.rotate_by(self, q: ndarray, inplace: bool = False, order: str = 'H') ndarray#

Rotate all Quaternions in the array around quaternion \(\mathbf{q}\).

Parameters:
  • q (numpy.ndarray or ahrs.Quaternion) – 4 element array to rotate around. It can be given as a list, tuple, numpy.ndarray, or an ahrs.Quaternion object. It will be normalized to be a unit quaternion.

  • inplace (bool, default: False) – If False, return a copy. Otherwise, do operation inplace, replace values in array and return None.

  • order (str, default: ‘H’) – Order of the elements in the quaternion. Can be 'H' (Hamilton) or 'S' (Scipy).

Returns:

Q’ – N-by-4 array with all Quaternions rotated around q.

Return type:

numpy.ndarray

Examples

>>> qts = np.tile([1., -2., 3., -4], (5, 1))    # Five equal arrays
>>> v = np.random.randn(5, 4)*0.1               # Gaussian noise
>>> Q = QuaternionArray(qts + v)
>>> Q.view()
QuaternionArray([[ 0.18873724, -0.36700234,  0.57194646, -0.70891804],
                 [ 0.21652608, -0.37263592,  0.54594733, -0.71847091],
                 [ 0.19481676, -0.38515671,  0.54045061, -0.72222841],
                 [ 0.16899238, -0.3725492 ,  0.56720371, -0.71479271],
                 [ 0.17139691, -0.36373225,  0.5687926 , -0.71749351]])
>>> q = Quaternion([-1., 2., -3., 4.])          # Quaternion to rotate about
>>> Q.rotate_by(q)
array([[ 0.93054027,  0.10652202, -0.21695865,  0.27509419],
       [ 0.92025996,  0.14191701, -0.22805842,  0.28455321],
       [ 0.92852888,  0.14234816, -0.22293603,  0.26051995],
       [ 0.93786314,  0.10700622, -0.20718376,  0.25697719],
       [ 0.9370473 ,  0.10659342, -0.20136569,  0.26463573]])