Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2011-03-09 16:02:36

Frankinstien
Member
Registered: 2011-03-09
Posts: 2

finding adjacent cubes in n dimensions

Hello,

I'm trying to figure out how to find all adjacent cubes in a hypercube of any matrix size. So for instance a 3x3x3 cube matrix in 3 dimensions has positions:

Idx   X      Y       Z
0    1    1    1
1    1    1    2
2    1    1    3

3    1    2    1
4    1    2    2
5    1    2    3

6    1    3    1
7    1    3    2
8    1    3    3

9    2    1    1
10    2    1    2
11    2    1    3

12    2    2    1
13    2    2    2
14    2    2    3

15    2    3    1
16    2    3    2
17    2    3    3

18    3    1    1
19    3    1    2
20    3    1    3

21    3    2    1
22    3    2    2
23    3    2    3

24    3    3    1
25    3    3    2
26    3    3    3

Each index represents a cube with x, y z coordinates, I want to be able to find all the adjacent cubes and their indices either by the x, y, z ordinal and/or the index within the matrix.

Appreciate any help, thx.

Offline

#2 2011-03-09 18:42:23

Frankinstien
Member
Registered: 2011-03-09
Posts: 2

Re: finding adjacent cubes in n dimensions

Figured out how to iterate through the matrix using the x,y,z ordinals, they aren't really coordinates but are a scheme of a class object that can dynamically emulate n dimensional arrays, I was just testing it with 3 dimensions.  The solution was to test upper and lower bounds of each dimension of the array and then by virtue of the number of cubes in the matrix index the adjacent cubes by incrementing and decrementing each dimension by one.  You also have to weed out the diagonal cubes...

Last edited by Frankinstien (2011-03-09 18:45:34)

Offline

Board footer

Powered by FluxBB