/* Copyright 2002 David Joiner and the Shodor Education Foundation, Inc. Shodor general use license This code is provided as is, and is offered with no guarantee. This code may be used freely in any non commercial product. Any works using this code must publicly give credit for this work to the Shodor Education Foundation, and should provide in that credit a link to the location of the code on the Computational Science Education Reference Desk (http://www.shodor.org/cserd) as well as to the Shodor Education Foundation (http://www.shodor.org) and to any other authors listed in the copyright statement found within the code. Copyright statements within the code may not be modified. This license does not grant permission for use in any commercial product. */ #include "SphericalHarmonic.h" #include "AssocLegendre.h" #include "Complex.h" #include "factorial.h" #include SphericalHarmonic::SphericalHarmonic() { l=0; m=0; } SphericalHarmonic::SphericalHarmonic(int l,int m) { this->l=l; this->m=m; } SphericalHarmonic::~SphericalHarmonic() { } void SphericalHarmonic::setL(int l) { this->l=l; } void SphericalHarmonic::setM(int m) { this->m=m; } void SphericalHarmonic::setLM(int l,int m) { this->l=l; this->m=m; } int SphericalHarmonic::getL() { return l; } int SphericalHarmonic::getM() { return m; } Complex SphericalHarmonic::eval(double theta, double phi) { int absm=abs(m); double sign; if (absm%2==1) sign=-1.0; else sign=1.0; AssocLegendre P(l,absm); Complex retval(0.0,(double)absm*phi); retval=retval.exp(); double factor=sign* sqrt((double)(2*l+1)/(4.0*M_PI)* factorial(l-m)/factorial(l+m))* P.eval(cos(theta)); retval=retval.times(factor); if (m<0) { retval=retval.conjugate(); retval=retval.times(sign); } return retval; }