Skip to content

Instantly share code, notes, and snippets.

@kugimasa
Last active May 26, 2020 04:35
Show Gist options
  • Save kugimasa/01103e58ae2c0e54a3d4c9d47d88466d to your computer and use it in GitHub Desktop.
Save kugimasa/01103e58ae2c0e54a3d4c9d47d88466d to your computer and use it in GitHub Desktop.
Sampling a direction on hemisphere uniformly
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
@kugimasa
Copy link
Author

kugimasa commented May 22, 2020

UniformSampling

Using 1000 samples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment