Return a random unit direction vector. If shape = (n1, n2), the function returns (n1, n2, 3).
(*shape, rng: np.random.RandomState = None)
| 344 | |
| 345 | |
| 346 | def 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 | |
| 365 | def get_random_direction_within_cone( |
no outgoing calls
no test coverage detected