e3x.so3.rotations.random_rotation

e3x.so3.rotations.random_rotation(key, perturbation=1.0, num=1)[source]

Samples a random \(3\times3\) rotation matrix.

Samples random \(3\times3\) rotation matrices from \(\mathrm{SO(3)}\). The perturbation parameter controls how strongly random points on a sphere centered on the origin are perturbed by the rotation. For perturbation=1.0, any point on the sphere is rotated to any other point on the sphere with equal probability. If perturbation<1.0, returned rotation matrices are biased to identity matrices. For example, with perturbation=0.5, a point on the sphere is rotated to any other point on the same hemisphere with equal probability.

Example

>>> import jax
>>> import e3x
>>> e3x.so3.random_rotation(jax.random.PRNGKey(0), perturbation=1.0)
Array([[-0.93064284, -0.11807037,  0.34635717],
       [ 0.33270139,  0.1210826 ,  0.9352266 ],
       [-0.15236041,  0.9855955 , -0.07340252]], dtype=float32)
>>> e3x.so3.random_rotation(jax.random.PRNGKey(0), perturbation=0.0)
Array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]], dtype=float32)
Parameters:
  • key (<class 'UInt32[Array, '2']'>) – A PRNG key used as the random key.

  • perturbation (float, default: 1.0) – A value between 0.0 and 1.0 that determines the perturbation.

  • num (int, default: 1) – Number of returned rotation matrices.

Return type:

Union[Float[Array, '3 3'], Float[Array, 'num 3 3']]

Returns:

An Array of shape \((\mathrm{num}, 3, 3)\) or \((3, 3)\) (if num = 1) representing random \(3\times3\) rotation matrices.