MCPcopy Create free account
hub / github.com/apple/ml-pointersect / get_random_direction

Function get_random_direction

plib/rigid_motion.py:346–362  ·  view source on GitHub ↗

Return a random unit direction vector. If shape = (n1, n2), the function returns (n1, n2, 3).

(*shape, rng: np.random.RandomState = None)

Source from the content-addressed store, hash-verified

344
345
346def get_random_direction(*shape, rng: np.random.RandomState = None):
347 """
348 Return a random unit direction vector.
349
350 If shape = (n1, n2), the function returns (n1, n2, 3).
351 """
352
353 if len(shape) == 0:
354 shape = []
355
356 if rng is None:
357 vs = np.random.randn(*shape, 3)
358 else:
359 vs = rng.randn(*shape, 3)
360 vs = vs / np.linalg.norm(vs, axis=-1, keepdims=True)
361
362 return vs
363
364
365def get_random_direction_within_cone(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected