We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › get coords from linear array
Page Index Toggle Pages: 1
get coords from linear array (Read 608 times)
get coords from linear array
Jun 19th, 2006, 9:32pm
 
From the pixels[] array which is singular in dimensions we can extrapolate a two dimensional locale in the following fashion:
Code:

int x = pixels.length % width;
int y = pixels.length / width;

If a length of string can become a square, surely it can become a cube:
Code:

x = (n % (width * height) % width;
y = (n % (width * height)) / width;
z = n / (width * height);

I felt from this point I should be able to create an algorithm that given "n" a point on a one dimensional array, one should be able to give an array of dimensions (d[]) and receive an array of the where that point is in your defined abstract space.
Code:

//4d
x = (n % (d[0] * d[1] * d[2])) % (d[0] * d[1]) % d[0];
y = (n % (d[0] * d[1] * d[2])) % (d[0] * d[1]) / d[0];
z = (n % (d[0] * d[1] * d[2])) / (d[0] * d[1]);
h = n / (d[0] * d[1] * d[2]);

//5d
0 = (n % (d[0] * d[1] * d[2] * d[3])) % (d[0] * d[1] * d[2]) % (d[0] * d[1]) % d[0];
1 = (n % (d[0] * d[1] * d[2] * d[3])) % (d[0] * d[1] * d[2]) % (d[0] * d[1]) / d[0];
2 = (n % (d[0] * d[1] * d[2] * d[3])) % (d[0] * d[1] * d[2]) / (d[0] * d[1]);
3 = (n % (d[0] * d[1] * d[2] * d[3])) / (d[0] * d[1] * d[2]);
4 = n / (d[0] * d[1] * d[2] * d[3]);

There's a logical pattern to what's going on here, I can't see how to implement it just now. I have tested each of these equations and they seem to hold true. The trick seems to be to modulo through the dimensions till you're at point where you can measure down (except when measuring x) and then divide by the multiple of the dimensions below that dimension. Any suggestions?
Page Index Toggle Pages: 1