Skip to content

Instantly share code, notes, and snippets.

@gerwang
Last active October 10, 2019 10:05
Show Gist options
  • Save gerwang/3f8d45e9d793150629d9b471326afaf0 to your computer and use it in GitHub Desktop.
Save gerwang/3f8d45e9d793150629d9b471326afaf0 to your computer and use it in GitHub Desktop.
python code to compute spherical harmonics
import numpy as np
sh = np.zeros(9)
sh[0] = 1 / np.sqrt(4 * np.pi)
sh[1:4] = 2 * np.pi / 3 * np.sqrt(3 / (4 * np.pi))
sh[4] = np.pi / 8 * np.sqrt(5 / (4 * np.pi))
sh[5:8] = 3 * np.pi / 4 * np.sqrt(5 / (12 * np.pi))
sh[8] = 3 * np.pi / 8 * np.sqrt(5 / (12 * np.pi))
def calc_sh_light(x, y, z):
res = np.zeros(9)
res[0] = sh[0];
res[1] = sh[1] * z;
res[2] = sh[2] * y;
res[3] = sh[3] * x;
res[4] = sh[4] * (2 * z * z - x * x - y * y);
res[5] = sh[5] * y * z;
res[6] = sh[6] * x * z;
res[7] = sh[7] * x * y;
res[8] = sh[8] * (x * x - y * y);
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment