Random Attitudes#
- ahrs.common.quaternion.random_attitudes(n: int = 1, representation: str = 'quaternion') ndarray#
Generate random attitudes
To generate a random quaternion a mapping in SO(3) is first created and then transformed as explained originally by [Sho92] and summarized in [Kuf04].
First, three uniform random values are sampled from the interval [0, 1]:
\[u_1, u_2, u_3 \sim U(0, 1)\]Then, two random angles are generated from these values:
\[\begin{split}\begin{array}{rl} s_1 &= \sqrt{1-u_1} \\ s_2 &= \sqrt{u_1} \\ t_1 &= 2\pi u_2 \\ t_2 &= 2\pi u_3 \end{array}\end{split}\]Finally, the quaternion is built as:
\[\begin{split}\mathbf{q} = \begin{bmatrix} s_2\cos t_2 \\ s_1\sin t_1 \\ s_1\cos t_1 \\ s_2\sin t_2 \end{bmatrix}\end{split}\]- 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
>>> random_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]], [[ 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]]])