Page 1 of 1

### "02 sequence" distribution ?

Posted: Tue Apr 03, 2012 8:40 am
Hi All,

Once again I'm playing with the 02-sequence (VDC+Sobol) and have used a small "processing"(java) function to simulate samples distribution over an image.
02sequence.png (27.6 KiB) Viewed 2767 times
I have do the following test, I center all my points and the image is completely black. The result I expected first ! Does someone has an explanation ?

Code: Select all

``````int NUM_POINTS = 512*512;
int W = 512;
int H = 512;

void setup()
{
size(W,H);
background(0);
stroke(255);
noLoop();

drawSamples();
}

void draw()
{
}

void drawSamples()
{
for(int j = 0; j < NUM_POINTS; j++)
{
float x = VanDerCorput(j, 0); // == Halton base 2
float y = Sobol2(j, 0);
//point(0.5f + x*width, 0.5f + y*height);
point(x*width, y*height);
}
}

float VanDerCorput(int n, int scramble)
{
n = (n << 16) + (n >>> 16);
n = ((n & 0x00ff00ff) << 8) | ((n & 0xff00ff00) >>> 8);
n = ((n & 0x0f0f0f0f) << 4) | ((n & 0xf0f0f0f0) >>> 4);
n = ((n & 0x33333333) << 2) | ((n & 0xcccccccc) >>> 2);
n = ((n & 0x55555555) << 1) | ((n & 0xaaaaaaaa) >>> 1);
n ^= scramble;

return ((n>>>8) & 0xffffff) / (float)(1 << 24);
//return (float)n / (float)(1 << 24);
}

float Sobol2(int n, int scramble)
{
for (int v = 1 << 31; n != 0; n >>>= 1, v ^= v >>> 1)
if ((n & 1) > 0) scramble ^= v;

return (float)((scramble>>>8) & 0xffffff) / (float)(1 << 24);
//return (float)scramble / (float)(1 << 24);
//return (float)scramble / (float)0x100000000LL;
}

int Hash(long aNumber)
{
aNumber = (aNumber + 0x7ed55d16) + (aNumber << 12);
aNumber = (aNumber ^ 0xc761c23c) ^ (aNumber >>> 19);
aNumber = (aNumber + 0x165667b1) + (aNumber << 5);
aNumber = (aNumber + 0xd3a2646c) ^ (aNumber << 9);
aNumber = (aNumber + 0xfd7046c5) + (aNumber << 3);
aNumber = (aNumber ^ 0xb55a4f09) ^ (aNumber >>> 16);

return (int)aNumber;
}
``````