说我有5×5的栅格,并在从0-24编号网格每个单元,打算从左至右。给定一个手机号码,如17,我该如何确定,该单元的X和Y坐标?我已经能够做到这一点,反之亦然,在那里,如果给出的坐标,我可以计算出细胞数:
Say I have a grid of 5x5, with each cell in the grid numbered from 0-24, going from left to right. Given a cell number such as 17, how do I determine that cell's x and y coordinates? I've been able to do it vice versa, where if given the coordinates I can calculate cell number:
Cellnumber = X + Y *宽度
(x和y坐标重新present左上点每个电池单元的)
Cellnumber = x + y∗width
(The x and y coordinates represent the upper left point of each cell)
但现在我想的正好相反。任何想法?
But now I want the opposite. Any ideas?
假设基于0的坐标和一个类似C的语法,这将是这样的:
Assuming 0-based coordinates and a C-like syntax, it would be something like this:
int y = Cellnumber / width;
int x = Cellnumber % width;