ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/spharm.cal
Revision: 1.2
Committed: Wed Feb 9 17:28:36 2005 UTC (19 years, 2 months ago) by greg
Branch: MAIN
Changes since 1.1: +1 -0 lines
Log Message:
Forgot RCSid

File Contents

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