Skip to content

Instantly share code, notes, and snippets.

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

kugimasa commented May 22, 2020

CosineLobe(N=1)
CosineLobe(N=2)
CosineLobe(N=10)

Using 1000 samples

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