翻译在电网XY坐标顺序分配的号码 [英] Translate sequentially assigned number in grid to x-y coordinates

查看:123
本文介绍了翻译在电网XY坐标顺序分配的号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有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;

这篇关于翻译在电网XY坐标顺序分配的号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆