{ RCSid $Id: sphsamp.cal,v 1.3 2005/02/15 23:45:14 greg Exp $ }
{
	Jittered sampling of a sphere

	2/15/2005	G. Ward

	Constant:
		N -		total number of samples on sphere
	Input:
		i -		sample number [0,N-1]
	Output:
		theta	- polar angle (0-PI)
		phi_un	- azimuthal angle (unnormalized)
		phi	- azimuthal angle (0-2*PI)
		Dx	- X-component of direction vector
		Dy	- Y-component of direction vector
		Dz	- Z-component of direction vector
}
S : .7;			{ jitter amount (0-1) }

k : 2*sqrt(PI/N);	{ k^2 is solid angle of each sample }

mod(n,d) : n - floor(n/d)*d;

alpha0 = asin(2/N*(i+.5) - 1);

theta = alpha0 + PI/2 + k*S*(rand(.35*i+10.3) - .5);
phi_un = sqrt(PI*N)*alpha0 + k*S*(rand(-.83*i-17.9) - .5);
phi = mod(phi_un, 2*PI);

sint = sin(theta);
Dx = cos(phi)*sint;
Dy = sin(phi)*sint;
Dz = cos(theta);
