# 3D array. How do I find the outermost indices?

This topic is 3168 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I create a 3D array of variable width, height and depth:
        public void CreateNewLevel(int width, int height, int depth)
{
array3D = new int[width, height, depth];

for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y)
{
for (int z = 0; z < depth; ++z)
{

}
}
}
}


How can I find the outermost indices? Would it be something along the line of checking if x - 1 < 0 || y - 1 < 0 || z - 1 < 0 x + 1 == width || y + 1 == height || z + 1 == depth? EDIT: Is this correct?
        public void CreateNewLevel(int width, int height, int depth)
{
map3D = new int[width, height, depth];

for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y)
{
for (int z = 0; z < depth; ++z)
{
bool a = x == 0 || y == 0 || z == 0;
bool b = x + 1 == width || y + 1 == height || z + 1 == depth;
map3D[x, y, z] = a || b ? 1 : 0;
}
}
}
}


or can anyone see any cases where it wouldn't work?

##### Share on other sites
The extremities of the level are in the slices where x, y, or z is 0 or (size - 1). Is that what you want? The corners are in the intersections of these slices (logical AND).

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×