Need help?
<- Back

Comments (19)

  • evanb
    In case the author is reading this, if you're going to introduce the complex-valued harmonics you should be careful to put the complex conjugate in the inner product <f, g> = ∫ f(ω)^* g(ω) dω which does match the corresponding linear-algebra inner product if the vectors are over the complex numbers p . q = Σ_i p^*_i q_i which guarantees that p.p ≥ 0 even for complex p (and does not change the only-real case).
  • maho
    +1 for introducing them as real-valued functions over cartesian coordinates!Typically, spherical harmonics are introduced as a complex function over spherical coordinates, which makes them much easier to derive, but imo hides their beauty.The real-valued, cartesian form of regular spherical harmonics is also called "solid harmonics" or "harmonic polynomials", in case you want to dig deeper.
  • hasley
    If one needs to describe (and maybe compress) functions or data on a sphere, spherical harmonics are really a thing.An alternative would be to construct a new function (or matrix) that is not only periodic in azimuth, but also in elevation (i.e., extend elevation to a full circle -pi to +pi). Then, one can simply compute two independent Fourie r transforms: along azimuth and along elevation. [1] The same idea works on matrices using the Discrete Fourier transform (DFT/FFT). However, you then have to accept things like that your data points are all equal at the poles.[1] https://en.wikipedia.org/wiki/Double_Fourier_sphere_method
  • hackingonempty
    > spherical harmonics can have uses beyond lightingThis math is also used in Ambisonic surround sound though newer techniques use planewave expansion.For games, the full-sphere encoding of Ambisonic B-format can be decoded for arbitrary speaker locations and the soundfield rotated around any axis. I'm not sure if its ever been used for a game though.
  • lukko
    This is really great. I always saw those harmonic shapes as electron orbitals, I had no idea they could be used in lighting too - so cool.It made me wonder - why do the electron orbitals take those shapes in say a hydrogen atom? Is there a constraint on the electron and proton together that make it fit only to spherical harmonic functions?
  • vatsachak
    Awesome write up. Is the appeal of spherical harmonics in graphics compression?Like, if you know the third order harmonics that's only 16 values you have to pass around
  • nice_byte
    Author here. Please let me know if the sample code doesn't work for you. It's all single threaded dumb JavaScript which makes it very easy to read, but definitely not performant. I decided to stick with it for didactic reasons, but still worried that it may hang someone's browser.