Commit 4ef260f524fb39c85ab471deaad4267c0a9ddf90

Authored by Sebastian Berisha
2 parents eddf63c1 e3b53161

Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib

Showing 1 changed file with 14 additions and 2 deletions   Show diff stats
stim/math/spharmonics.h
... ... @@ -25,8 +25,20 @@ protected:
25 25 //calculate the value of the SH basis function (l, m) at (theta, phi)
26 26 //here, theta = [0, PI], phi = [0, 2*PI]
27 27 double SH(int l, int m, double theta, double phi){
28   - std::complex<T> result = boost::math::spherical_harmonic(l, m, phi, theta);
29   - return result.imag() + result.real();
  28 + //std::complex<T> result = boost::math::spherical_harmonic(l, m, phi, theta);
  29 + //return result.imag() + result.real();
  30 +
  31 + //this calculation is based on calculating the real spherical harmonics:
  32 + // https://en.wikipedia.org/wiki/Spherical_harmonics#Addition_theorem
  33 + if (m < 0) {
  34 + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, abs(m), phi, theta).imag();
  35 + }
  36 + else if (m == 0) {
  37 + return boost::math::spherical_harmonic(l, m, phi, theta).real();
  38 + }
  39 + else {
  40 + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, m, phi, theta).real();
  41 + }
30 42 }
31 43  
32 44 unsigned int coeff_1d(unsigned int l, int m){
... ...