ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/sphsamp.cal
Revision: 1.1
Committed: Sat Feb 22 02:07:21 2003 UTC (21 years, 2 months ago) by greg
Branch: MAIN
CVS Tags: rad3R5, rad3R6, rad3R6P1
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# User Rev Content
1 greg 1.1 {
2     Uniform sampling of sphere
3    
4     Define:
5     N - total number of samples
6     i - sample number
7    
8     Output:
9     theta - polar angle (degrees)
10     phi - azimuthal angle (degrees)
11     Dx - X-component of direction vector
12     Dy - Y-component of direction vector
13     Dz - Z-component of direction vector
14     }
15    
16     DEGREE : PI/180;
17     bound(a,x,b) : if(a-x, a, if(x-b, b, x));
18     Acos(x) : acos(bound(-1,x,1));
19     Sqrt(x) : if(x, sqrt(x), 0);
20    
21     nalt = floor(sqrt(2/PI*N) + .5);
22     nazi = floor(PI/2*nalt + .5);
23    
24     cond = nalt*nazi-.9999 - i;
25    
26     ialt = floor(i/nazi);
27     iazi = i - ialt*nazi;
28    
29     ralt = (ialt + rand(i*.328+.112))/nalt;
30     razi = (iazi + rand(i*-.731+.318))/nazi;
31    
32     rtheta = Acos(Dz);
33     rphi = 2*PI*razi;
34     Dxy = Sqrt(1 - Dz*Dz);
35     theta = rtheta/DEGREE;
36     phi = rphi/DEGREE;
37     Dx = Dxy*cos(rphi);
38     Dy = Dxy*sin(rphi);
39     Dz = 1 - 2*ralt;