Last active
May 26, 2020 04:35
-
-
Save kugimasa/01103e58ae2c0e54a3d4c9d47d88466d to your computer and use it in GitHub Desktop.
Sampling a direction on hemisphere uniformly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def uniform_hemisphere(): | |
# Sampling 2 random numbers | |
u_1 = np.random.rand() | |
u_2 = np.random.rand() | |
# Angles | |
phi = 2 * np.pi * u_1 | |
theta = np.pi / 2 * u_2 | |
x = np.sin(theta) * np.cos(phi) | |
y = np.sin(theta) * np.sin(phi) | |
z = np.cos(theta) | |
return x, y, z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using 1000 samples