An unintuitive lesson in Monte Carlo sampling
I learnt this the hard way today.
To uniformly sample the interior of a given circle, we have to be careful when working in the polar domain; i.e. randomizing an angle and a distance from the center. If the randomized distance is uniformly distributed, the resulting points will be heavily weighted toward the center. It’s only blindingly obvious when you stop to think about it…
If rand() produces a uniformly distributed continuous value [0, 1), then
randAngle = rand() * 2 * PI;
randDistance = rand() * radius;
randCoordinates = getCartesian(randAngle, randDistance); //THIS IS WRONG!
For anyone who wants to know, using
randDistance = sqrt(rand()) * radius;
fixes this.
Gary :: Feb.11.2009 :: General, w00t! :: No Comments »