algorithm - How to get all 24 rotations of a 3-dimensional array? -


i have 3-dimensional array. think of brick. there 24 possible rotations of brick (that keep edges parallel coordinate axes). how generate corresponding 3-dimensional arrays?

a die (half pair of dice) handy observing 24 different orientations, , can suggest operation sequences generate them. see of 6 faces can uppermost, , sides below can rotated 4 different cardinal directions. let denote 2 operations: “turn” , “roll”, turn rotates die z axis 1 cardinal next, , roll rotates die 90° away you, away-face becomes bottom face , near face top. these operations can expressed using rotation matrices mentioned in answer of felipe lopes, or can expressed simple functions when given (x,y,z) return (-y,x,z) or (x,z,-y), respectively.

anyhow, if place die 1 on near face, 2 @ right, , 3 on top, find following sequence of steps generates twelve different orientations 1, 2, or 3 spots on top: rtttrtttrttt. sequence rtr exposes 6, 4, 5 1, 2, 3 were, , repeat of sequence rtttrtttrttt generates twelve orientations 4, 5, or 6 spots on top. mentioned sequence embedded in following python code.

def roll(v): return (v[0],v[2],-v[1]) def turn(v): return (-v[1],v[0],v[2]) def sequence (v):     cycle in range(2):         step in range(3):  # yield rttt 3 times             v = roll(v)             yield(v)           #    yield r             in range(3): #    yield ttt                 v = turn(v)                 yield(v)         v = roll(turn(roll(v)))  # rtr  p = sequence(( 1, 1, 1)) q = sequence((-1,-1, 1)) in sorted(zip(p,q)):     print 

the rationale printing out sorted list of transformed pairs of points twofold: (i) face orientation can specified locations of 2 of corners; (ii) easy check uniqueness of each pair, eg piping output uniq.

here how sorted output begins:

((-1, -1, -1), (-1, 1, 1)) ((-1, -1, -1), (1, -1, 1)) ((-1, -1, -1), (1, 1, -1)) ((-1, -1, 1), (-1, 1, -1)) ((-1, -1, 1), (1, -1, -1)) ((-1, -1, 1), (1, 1, 1)) ((-1, 1, -1), (-1, -1, 1)) ((-1, 1, -1), (1, -1, -1)) ((-1, 1, -1), (1, 1, 1)) 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -