Skip to content

Instantly share code, notes, and snippets.

@joonahn
Created November 5, 2021 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonahn/607f78e8339283f605b8f89cf5199172 to your computer and use it in GitHub Desktop.
Save joonahn/607f78e8339283f605b8f89cf5199172 to your computer and use it in GitHub Desktop.
create 24 unique 3x3 cube rotation matrices.
# the algorithm is from https://stackoverflow.com/questions/16452383/how-to-get-all-24-rotations-of-a-3-dimensional-array
import nunpy as np
rollmat = np.array([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype=np.float)
turnmat = np.array([[0, -1, 0], [1, 0, 0], [0, 0, 1]], dtype=np.float)
def get_24_rotation():
rotations = []
current_rot = np.eye(3)
for cycle in range(2):
for step in range(3): # RTTT 3 times
current_rot = rollmat @ current_rot
rotations.append(current_rot) # R
for i in range(3): # TTT
current_rot = turnmat @ current_rot
rotations.append(current_rot)
current_rot = rollmat @ turnmat @ rollmat @ current_rot # RTR
return rotations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment