SZanlongo
4/3/2015 - 3:04 PM

Translate sequentially assigned number in grid to x-y coordinates From http://stackoverflow.com/questions/5750855/translate-sequentially-as

Translate sequentially assigned number in grid to x-y coordinates

From http://stackoverflow.com/questions/5750855/translate-sequentially-assigned-number-in-grid-to-x-y-coordinates

// Given grid of width * height, with each cell in the grid numbered from 0-n, going from left to right, determine that cell's x, y coordinates given the cell number.

int cellNumber = x + y * h; // cellNumber

int y = cellNumber / w; // y
int x = cellNumber % w; // x