-
Notifications
You must be signed in to change notification settings - Fork 945
Closed
Description
Maybe I'm reading this incorrectly but what the code does doesn't seem to match the function name. The current code appears to do a uniform distribution on cylinder and then stretch to a sphere. Doesn't that raise the probability of points near the poles?
vec3 random_unit_vector() {
auto a = random_double(0, 2*pi);
auto z = random_double(-1, 1); // uniform in z means the same # of hits over less surface area
auto r = sqrt(1 - z*z);
return vec3(r*cos(a), r*sin(a), z);
}
I was expecting something more like this:
vec3 random_unit_vector() {
auto a = random_double(0, 2 * pi);
auto b = random_double(-pi/2, pi/2);
auto z = sin(b);
auto r = sqrt(1 - z * z);
return vec3(r * cos(a), r * sin(a), z);
}