Get positional data from index on a 2D-field
Say I had three variables (On a 2D-field):
NumSquares, WindowSize (Both X and Y has this value), Index
So if, for example, NumSquares were 8, WindowSize 256 and Index was at 64; How would the algorithm to get positional data 开发者_运维知识库out of these variables look?
I assume that by "positional data" you mean coordinates on the grid. And index means position of the tile in linearized array calculated with formula X + width * Y
. Then:
X = index % width
Y = index / width
I'm not sure what language you are working in, so just to be sure: % is modulo, / is in this context integer division.
精彩评论