ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/spharm.cal
Revision: 1.1
Committed: Wed Feb 9 17:27:51 2005 UTC (19 years, 2 months ago) by greg
Branch: MAIN
Log Message:
Created spherical harmonics function for Katja Doerschner of NYU

File Contents

# Content
1 {
2 The first few Spherical Harmonics
3
4 Feb 2005 G. Ward
5 }
6 { Factorial (n!) }
7 fact(n) : if(n-1.5, n*fact(n-1), 1);
8
9 { Associated Legendre Polynomials 0-8 }
10 LegendreP2(n,m,x,s) : select(n+1,
11 select(m+1, 1),
12 select(m+1, x, s),
13 select(m+1, .5*(3*x*x - 1), 3*x*s, 3*(1-x*x)),
14 select(m+1, .5*x*(5*x*x-3), 1.5*(5*x*x-1)*s, 15*x*(1-x*x), 15*s*s*s),
15 select(m+1,
16 .125*(3 + x*x*(-30 + x*x*35)),
17 2.5*x*(-3 + x*x*7)*s,
18 7.5*(7*x*x-1)*(1-x*x),
19 105*x*s*s*s,
20 105*s*s*s*s),
21 select(m+1,
22 .125*x*(15 + x*x*(-70 + x*x*63)),
23 1.875*s*(1 + x*x*(-14 + x*x*21)),
24 52.5*x*(1-x*x)*(3*x*x-1),
25 52.5*s*s*s*(9*x*x-1),
26 945*x*s*s*s*s,
27 945*s*s*s*s*s),
28 select(m+1,
29 .0625*(-5 + x*x*(105 + x*x*(-315 + x*x*231))),
30 2.625*(5 + x*x*(-30 + x*x*33))*s,
31 13.125*s*s*(1 + x*x*(-18 + x*x*33)),
32 157.5*(11*x*x-3)*x*s*s*s,
33 472.5*s*s*s*s*(11*x*x-1),
34 10395*x*s*s*s*s*s,
35 10395*s*s*s*s*s*s),
36 select(m+1,
37 .0625*x*(-35 + x*x*(315 + x*x*(-693 + x*x*429))),
38 .4375*s*(-5 + x*x*(135 + x*x*(-495 + x*x*429))),
39 7.875*x*s*s*(15 + x*x*(-110 + x*x*143)),
40 39.375*s*s*(1 + x*x*(-18 + x*x*33)),
41 157.5*(11*x*x-3)*x*s*s*s,
42 472.5*s*s*s*s*(11*x*x-1),
43 10395*x*s*s*s*s*s,
44 10395*s*s*s*s*s*s),
45 select(m+1,
46 .0078125*(35 + x*x*(-1260 + x*x*(6930 + x*x*(-12012 + x*x*6435)))),
47 .5625*x*s*(-35 + x*x*(385 + x*x*(-1001 + x*x*715))),
48 19.6875*s*s*(-1 + x*x*(33 + x*x*(-143 + x*x*143))),
49 433.125*x*s*s*s*(3 + x*x*(-26 + x*x*39)),
50 1299.375*s*s*s*s*(1 + x*x*(-26 + x*x*65)),
51 67567.5*x*s*s*s*s*s*(5*x*x-1),
52 67567.5*s*s*s*s*s*s*(15*x*x-1),
53 2027025*x*s*s*s*s*s*s*s,
54 2027025*s*s*s*s*s*s*s*s)
55 );
56 { Relation for Legendre with -M }
57 odd(n) : .5*n - floor(.5*n) - .25;
58 LegendreP(n,m,x) : if(m+.5,
59 LegendreP2(n,m,x,sqrt(1-x*x)),
60 if(odd(-m),-1,1)*fact(n+m)/fact(n-m) *
61 LegendreP2(n,-m,x,sqrt(1-x*x))
62 );
63 { SH normalization factor }
64 SHnormF(l,m) : sqrt(0.25/PI*(2*l+1)*fact(l-m)/fact(l+m));
65 { Spherical Harmonics theta function }
66 SHthetaF(l,m,theta) : SHnormF(l,m)*LegendreP(l,m,cos(theta));
67
68 { Spherical Harmonic real portion }
69 SphericalHarmonicYr(l,m,theta,phi) : SHthetaF(l,m,theta)*cos(m*phi);
70 { Spherical Harmonic imag. portion }
71 SphericalHarmonicYi(l,m,theta,phi) : SHthetaF(l,m,theta)*sin(m*phi);
72
73 { Ordered, real SH basis functions }
74 SH_B4(l,m,o,theta,phi) : if(m-.5, if(o, SphericalHarmonicYi(l,m,theta,phi),
75 SphericalHarmonicYr(l,m,theta,phi)),
76 SHthetaF(l,0,theta) );
77 SH_B3(l,r,theta,phi) : SH_B4(l,floor((r+1.00001)/2),odd(r+1),theta,phi);
78 SH_B2(l,i,theta,phi) : SH_B3(l,i-l*l-1,theta,phi);
79 SphericalHarmonicB(i,theta,phi) : SH_B2(ceil(sqrt(i)-1.00001),i,theta,phi);
80
81 { Application of SH fitting coeff. f(i) }
82 SH_F2(n,f,theta,phi) : if(n-.5, f(n)*SphericalHarmonicB(n,theta,phi) +
83 SH_F2(n-1,f,theta,phi), 0);
84 SphericalHarmonicF(f,theta,phi) : SH_F2(f(0),f,theta,phi);