将1d数组索引转换为3d数组索引? [英] Convert a 1d array index to a 3d array index?

查看:54
本文介绍了将1d数组索引转换为3d数组索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要转换为3d数组索引的3个整数的整数,这是我正在研究的示例.

I've got a int that I want to convert to 3 ints for the index of a 3d array, here's an example of what I'm on about.

byte[,,] array = new byte[XSize, YSize, ZSize];

int i = 0;

//other code

array[#,#,#] = cur;

//other code

我不知道如何仅从i中获取#,#,#的正确数字.

I don't know how to get the correct numbers for the #,#,# from just i.

推荐答案

假设您要依次遍历Z,Y和X.

Supposing you want to iterate through Z, then Y, and then X. . .

int zDirection = i % zLength;
int yDirection = (i / zLength) % yLength;
int xDirection = i / (yLength * zLength); 

这篇关于将1d数组索引转换为3d数组索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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