[英]Get Index by X and Y
There's a way to get X and Y based on Index like有一种方法可以根据索引获取 X 和 Y
x = index % columns;
y = index / columns;
How can I reverse this and get Index based on X and Y?我怎样才能扭转这一局面并获得基于 X 和 Y 的索引?
Assuming we're dealing with integers here, if you have the following code:假设我们在这里处理整数,如果您有以下代码:
x = index % columns; // get the remainder of dividing index by columns
y = index / columns; // get the result of dividing index by columnsn
Then the reverse would be:那么反过来就是:
index = y * columns + x;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.