This blog post describes Qube, my Rubik's Cube simulator. Source code for Qube is now available in one single file from this link: Qube_osf.m. I will also submit the code to the MATLAB Central File Exchange. As usual, I welcome any feedback.
Here is the opening screen for Qube.
The cube is displayed in the center of the simulator.
The current stack is displayed in this text box over the cube.
Eighteen keys use Singmaster notation to generate rotations that are pushed onto the stack.
The two buttons at the lower right scramble the cube. The => button applies any rotations in the stack to the current cube. To apply them to Q0, use Q0 before =>
The ==> button is a toggle that generates repeated random rotations until it is turned off. A fresh scramble is produced every time I publish this file.
The two buttons at the lower left unscramble the cube. The <= button generates a rotation in the direction opposite the rotation at the top of the stack. This acts like a backspace. The <== toggle repeatedly backspaces until the stack is empty. This is the smart way to "solve" the puzzle -- remember how it was scrambled.
Let's unscramble the cube and get back to Q0.
The buttons in the left-hand group control the appearance of the simulator.
The vertices of the basic unit cubelet, qzero, are the eight combinations of +1 and -1, so the half-width of qzero is one. The twenty-seven cubelets in Q0 are scaled by this width parameter to produce gaps between the individual cubelets.
The number of fractional rotations in a quarter turn controls Qube's speed.
The cubelet centers are the points [x,y,z] where x, y and z are combinations of -2, 0 and 2. The cubelet type is the number of nonzeros in coordinates of its center, nnz([x,y,z]).
* 0: center * 1: face * 2: edge * 3: corner
An alternative to the traditional Rubik's colors made from the MATLAB axes color order.
This button turns on Handle Graphics rotate3d. You can then use your mouse to rotate the viewpoint. The visual effect is the same as rotating the entire cube.
The buttons in the right-hand group initiate computations. Other tools may be added.
Experimental solver. Greedy algorithm to minimize the sum of SVDs of the difference between the cubelets in the current cube and cubelets in Q0. Also known as the nuclear norm. It turns out that this solver does not work very well.
Number of repetitions to return to Q0. A fundamental notion in group theory.
Reinitialize without restarting.
Currently, the nuclear norm distance to Q0. Need something more sensitive to Rubik's cube patterns.
Number of rotations. Hence, the period.
Most recent rotation.
Pointer to this blog post.
The source code for Qube is available from this link: Qube_osf.m. The osf, one single file, format is a self-extracting archive that expands into a directory of individual functions.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.