[英]Two dimension array to single dimension and back again
I was trying to find information about transforming an index that has been converted from a 2 dimensional index , to a single one. 我试图找到有关将已从2维索引转换为索引的索引转换为单个索引的信息。 Then turn the single index back to a 2 dimensional one.
然后将单个索引转回到二维索引。 I don't even know what this method is called.
我甚至不知道这个方法叫什么。
formula to single index 公式为单指数
int index = x + y * width;
MyArray[index] ;
So my question is how do I turn it back into two dimensions? 所以我的问题是如何将其重新分为两个维度?
int x = index ??? width;
int y = index ??? width;
Can't wrap my head around it for some reason. 由于某种原因,无法绕过它。
Thanks 谢谢
int x = index % width;
int y = index / width;
x = index % width; x =指数%宽度; y = index / width;
y =索引/宽度;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.