| Build Status |
|---|
The purpose of this package is to provide methods to numerically handle real spherical harmonics expansions in Cartesian coordinates.
The normalized real spherical harmonics on the unit sphere are defined by
where
is the normalization factor and
are the associated Legendre polynomials which can be derived from the Legendre polynomials
Note that you will also find a convention in literature, where the
Each function
for all
The term
can be transformed from spherical to Cartesian coordinates, where it can be expressed as a homogeneous polynomial of degree
Generate a MultivariatePolynomials.Polynomial representation of
in variables α, β, and γ on the unit sphere by
using SphericalHarmonics
@polyvar α β γ
l = 7
m = -2
p = ylm(l,m,α,β,γ)
63.28217501963252αβγ⁵ - 48.67859616894809αβγ³ + 6.63799038667474αβγThe polynomial representation of
in variables x, y, and z on
@polyvar x y z
p = rlylm(l,m,x,y,z)
6.63799038667474x⁵yz + 13.27598077334948x³y³z - 35.40261539559861x³yz³ + 6.63799038667474xy⁵z - 35.40261539559861xy³z³ + 21.24156923735917xyz⁵In case where a function is equal to or can be approximated by a finite Spherical harmonic expansion
with
Coefficents c[l,m] = 42.0.
L = 2
c = SphericalHarmonicCoefficients(L)
c[0,0] = 42.0 #c₀₀
c[2,-1] = -1.0 #c₂₋₁
c[2,1] = 2.0 #c₂₁Internally, the coefficients are lexicographically stored in a vector (c[0,0], c[1,-1], c[1,0], c[1,1], c[2,-2], ...). So the above initialization is equivalent to
C = [42.0,0,0,0,0,-1,0,2,0]
c = SphericalHarmonicCoefficients(C)
f = sphericalHarmonicsExpansion(c,x,y,z)
2.1850968611841584xz + -1.0925484305920792yz + 11.847981254502882Note that SphericalHarmonicCoefficients(C) will throw an error if length(C) is not x, y, and z can be obtained by
@polyvar x y z
f = sphericalHarmonicsExpansion(c,x,y,z)
2.1850968611841584xz - 1.0925484305920792yz + 11.847981254502882Currently, expansions up to
If we change from a coordinate sytsem with coordinates x, y, and z into a translated one with new coordinates u = x + tx, v = y + ty, and w = z + tz we need transformed coefficients to express the expansion in these new coordinates. To this end, we can do
@polyvar u v w
translationVector = [0,0,1.0] # [tx,ty,tz]
cTranslated = translation(c,translationVector)
sphericalHarmonicsExpansion(cTranslated,u,v,w)
2.1850968611841584uw - 1.0925484305920792vw + 2.1850968611841584u - 1.0925484305920792v + 11.847981254502878If you want to evaluate MultivariatePolynomials
f(x=>0.5, y=>-1.0, z=>0.25)
12.394255469798921
f((x,y,z)=>(0.5,-1.0,0.25))
12.394255469798921In case where you want to evaluate
g = @fastfunc f
g(0.5,-1.0,0.25)
12.394255469798921which has moderate generation overhead. Usage from within local scope requires Base.invokelatest(foo, 1.0,2.0,3.0) instead of foo(1.0,2.0,3.0) to avoid issue #4. Or use
h = fastfunc(f)
h(0.5,-1.0,0.25)
12.394255469798921which uses GeneralizedGenerated for function generation and comes with a significant overhead.
For more informations on the MultivariatePolynomials package please visit the project page on github.