Last active
May 26, 2020 04:35
-
-
Save kugimasa/bbdb1ca6a29bfd015d5e19a396c0ed34 to your computer and use it in GitHub Desktop.
Sampling a direction on hemisphere using Cosine Lobe
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 cosine_lobe(N): | |
# Sampling 2 random numbers | |
u_1 = np.random.rand() | |
u_2 = 1.0 - np.random.rand() | |
# angles | |
phi = 2 * np.pi * u_1 | |
theta = np.arccos(np.power(u_2, 1/(N+1))) | |
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