如果我有从 0 开始的网格上位置的索引,如何将其转换为行、列?我得到以下错误结果。幸运的是,我知道我有多少行和列,在我的例子中是 11 x 11。
int column = position % columns;
int row = position / columns;
// x : horizontal position in range [0; columns-1]
// y : vertical position in range [0; rows-1]
int x = index % columns;
int y = index / columns;
int column = x + 1;
int row = y + 1;
扭转:
int index = x + y * columns;
or
int index = (column - 1) + (row - 1) * columns;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)