ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/sphsamp.cal
Revision: 1.2
Committed: Tue Feb 15 23:36:10 2005 UTC (19 years, 2 months ago) by greg
Branch: MAIN
Changes since 1.1: +17 -27 lines
Log Message:
Improved sampling algorithm to be more uniform over sphere (degrees -> radians)

File Contents

# User Rev Content
1 greg 1.2 { RCSid $Id$ }
2 greg 1.1 {
3     Uniform sampling of sphere
4 greg 1.2 2/15/2005 G. Ward
5 greg 1.1
6 greg 1.2 Constant:
7     N - total number of samples on sphere
8     Input:
9     i - sample number [0,N-1]
10 greg 1.1 Output:
11 greg 1.2 theta - polar angle (radians)
12     phi - azimuthal angle (radians)
13 greg 1.1 Dx - X-component of direction vector
14     Dy - Y-component of direction vector
15     Dz - Z-component of direction vector
16     }
17 greg 1.2 S : .7; { jitter amount (0-1) }
18 greg 1.1
19 greg 1.2 k : 2*sqrt(PI/N); { k^2 is solid angle of each sample }
20 greg 1.1
21 greg 1.2 alpha0 = asin(2/N*(i+.5) - 1);
22 greg 1.1
23 greg 1.2 theta = alpha0 + PI/2 + k*S*(rand(.35*i+10.3) - .5);
24     phi = sqrt(PI*N)*alpha0 + k*S*(rand(-.83*i-17.9) - .5);
25 greg 1.1
26 greg 1.2 sint = sin(theta);
27     Dx = cos(phi)*sint;
28     Dy = sin(phi)*sint;
29     Dz = cos(theta);