Chi-Tech
spherical_harmonics.cc
Go to the documentation of this file.
1#include "legendrepoly.h"
2
3#include "math/chi_math.h"
4#include <cmath>
5
6//###################################################################
7/**Implementation of the tesseral spherical harmonics.
8 *
9 * This code has a whitepaper associated with it
10 * <a href="SphericalHarmonics.pdf" target="_blank"><b>Spherical Harmonics</b></a>
11 * */
12double chi_math::Ylm(unsigned int ell, int m, double varphi, double theta)
13{
14 const int _ell = static_cast<int>(ell);
15 const int _m = std::abs(m);
16 const double Plm = AssocLegendre(ell,_m,cos(theta));
17
18 if (m<0)
19 {
20 return pow(-1.0, _m) *
21 sqrt(2.0 * Factorial(_ell - _m)/
22 Factorial(_ell + _m) ) *
23 Plm * sin(_m * varphi);
24 }
25 else if (m==0)
26 {
27 return Plm;
28 }
29 else
30 {
31 return pow(-1.0, _m) *
32 sqrt(2.0 * Factorial(_ell - _m)/
33 Factorial(_ell + _m) ) *
34 Plm * cos(_m * varphi);
35 }
36}
double Ylm(unsigned int ell, int m, double varphi, double theta)
double AssocLegendre(unsigned int ell, int m, double x)
double Factorial(int x)