diff --git a/stim/math/spharmonics.h b/stim/math/spharmonics.h index 266af7d..c51ee91 100644 --- a/stim/math/spharmonics.h +++ b/stim/math/spharmonics.h @@ -25,8 +25,20 @@ protected: //calculate the value of the SH basis function (l, m) at (theta, phi) //here, theta = [0, PI], phi = [0, 2*PI] double SH(int l, int m, double theta, double phi){ - std::complex result = boost::math::spherical_harmonic(l, m, phi, theta); - return result.imag() + result.real(); + //std::complex result = boost::math::spherical_harmonic(l, m, phi, theta); + //return result.imag() + result.real(); + + //this calculation is based on calculating the real spherical harmonics: + // https://en.wikipedia.org/wiki/Spherical_harmonics#Addition_theorem + if (m < 0) { + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, abs(m), phi, theta).imag(); + } + else if (m == 0) { + return boost::math::spherical_harmonic(l, m, phi, theta).real(); + } + else { + return sqrt(2.0) * pow(-1, m) * boost::math::spherical_harmonic(l, m, phi, theta).real(); + } } unsigned int coeff_1d(unsigned int l, int m){ -- libgit2 0.21.4