npplus.randomx module¶
Generate random random points and rotations in and on circles and spheres.
These functions are consistent with the numpy.random random(size) interface, in order to be compatible with the numerous other random distributions provided in numpy.random.
- incircle(size=None)[source]¶
Return uniform random points inside 2D unit circle.
- Parameters
size (int or tuple of int) – Leading axes of returned points. Final axis always length 2.
- Returns
xy – The random points inside the unit circle, trailing dimension 2.
- Return type
ndarray
- insphere(size=None)[source]¶
Return uniform random points inside 3D unit sphere.
- Parameters
size (int or tuple of int) – Leading axes of returnined points. Final axis always length 3.
- Returns
xyz – The random points inside the unit sphere, trailing dimension 3.
- Return type
ndarray
- oncircle(size=None)[source]¶
Return uniform random points on 2D unit circle.
- Parameters
size (int or tuple of int) – Leading axes of returned points. Final axis always length 2.
- Returns
xy – The random points on the unit circle, trailing dimension 2.
- Return type
ndarray
- onsphere(size=None)[source]¶
Return uniform random points on 3D unit sphere.
- Parameters
size (int or tuple of int) – Leading axes of returnined points. Final axis always length 3.
- Returns
xyz – The random points on the unit sphere, trailing dimension 3.
- Return type
ndarray
- rotation3(size=None)[source]¶
Return a collection of 3x3 random rotation matrices.
- Parameters
size (int or tuple of int, optional) – The number or leading dimensions of the 3x3 matrices returned.
- Returns
rotmat – A single 3x3 rotation matrix (that is, three orthogonal unit vectors in right-hand order) if size not given. Otherwise the dimensions specified by size are the leading dimensions of the collection of 3x3 rotation matrices.
- Return type
ndarray
Notes
By “random”, we mean that these matrices transform any single unit vector to a collection of unit vectors uniformly distributed over the surface of a sphere.
Uses the Arvo algorithm from Graphics Gems III. See http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/rand_rotation.c and http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.53.1357&rep=rep1&type=pdf and https://en.wikipedia.org/wiki/Rotation_matrix#Uniform_random_rotation_matrices