I am trying to create a program using Python 3 which must simulate the rotations of a cube.
However, I am struggling to figure out how to rotate that cube. I have the following formulas:
def rotate_x(self, angle):
""" Rotates the point around the X axis by the given angle in degrees. """
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
y = self.y * cosa - self.z * sina
z = self.y * sina + self.z * cosa
return Point3D(self.x, y, z)
def rotate_y(self, angle):
""" Rotates the point around the Y axis by the given angle in degrees. """
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
z = self.z * cosa - self.x * sina
x = self.z * sina + self.x * cosa
return Point3D(x, self.y, z)
def rotate_z(self, angle):
""" Rotates the point around the Z axis by the given angle in degrees. """
rad = angle * math.pi / 180
cosa = math.cos(rad)
sina = math.sin(rad)
x = self.x * cosa - self.y * sina
y = self.x * sina + self.y * cosa
return Point3D(x, y, self.z)
I run these functions on each vertex of the cube to rotate it. However, my problem is: how do I generate a list of all the possible rotations of the cube - rotating only by multiples of 90$^{\circ}$ or by 0$^{\circ}$ around the x, y, or z axes - while avoiding duplicates? I can rotate multiple times. I know there are 24 rotations - but what I'm wondering is how to generate them.
What I'm looking for is a list of all possible rotations (for example: 90$^{\circ}$x, 180$^{\circ}$y; 270$^{\circ}$x, 90$^{\circ}$z; 180$^{\circ}$y; etc) and an explanation of how you got to this list.
Such problems are tackled in group theory.
My friend Ruby gave me this list of rotations and some of the aliases she knows:
Note that $xy$ means the composition $x \circ y$, thus first applying $y$ and then applying $x$.
Here is the chat log and here is what I told Ruby about the problem. The latter one includes fancy ASCII graphics which explain how the permutations were defined.
The key ideas are
It should be possible to just use $x,y,z$ rotations, but then one needs a different mechanism to generate the tree of possible compositions. Counting seemed a quick hack.
These would be the compositions $yyx$ and $zzxxx$, which fall into the equivalence class $k = 17$.
References: