Random Attitudes
ahrs.common.quaternion.random_attitudes(n: int = 1, representation: str = 'quaternion') → ndarray : Generate random attitudes
code
To generate a random quaternion a mapping in SO(3) is first created and
then transformed as explained originally by [[Sho92](/u/fab8b0a9fec670cf#id69)] and
summarized in [[Kuf04](/u/fab8b0a9fec670cf#id37)].
First, three uniform random values are sampled from the interval [0, 1]:
Then, two random angles are generated from these values:
Finally, the quaternion is built as:
Parameters:
: - **n** (*int, default: 1*) – Number of random attitudes to generate. Default is 1.
- **representation** (str, default: `'quaternion'`) – Attitude representation. Options are `'quaternion'` or `'rotmat'`.
Returns:
: **Q** – Array of n random quaternions.
Return type:
: numpy.ndarray
Examples
```pythonrandom_attitudes() array([ 0.17607048, -0.42133834, -0.42445916, -0.78186163])
random_attitudes(1) array([ 0.50391486, 0.15642284, -0.04152787, -0.84845574])
random_attitudes(3) array([[-0.78506768, -0.21469241, 0.57654945, -0.07187942], [ 0.35614954, 0.78811481, 0.45912792, -0.20306182], [-0.2474619 , 0.21632585, 0.50492025, 0.79813613]])
random_attitudes(3, 'rotmat') array([[[-0.43297822, 0.69987831, -0.56806708], [-0.07346304, -0.65550383, -0.75161021], [-0.89840583, -0.28369892, 0.33523407]],
code
[[ 0.1082323 , -0.55111441, 0.82738061],
[-0.55001356, 0.66008952, 0.51163162],
[-0.82811283, -0.51044562, -0.23167739]],
[[ 0.19915247, 0.86104088, -0.46791762],
[-0.13040079, -0.44995169, -0.88348124],
[-0.97125379, 0.2369643 , 0.02267142]]])code