This blog post describesQube, my Rubik's Cube simulator. Source code forQubeis now available inone single filefrom 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 forQube.
The cube is displayed in the center of the simulator.
The current stack is displayed in this text box over the cube.
Eighteenkeysuse 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 toQ0, useQ0before=>
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 toQ0.
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 ofqzerois one. The twenty-seven cubelets inQ0are scaled by thiswidthparameter to produce gaps between the individual cubelets.
The number of fractional rotations in a quarter turn controlsQube'sspeed.
The cubelet centers are the points[x,y,z]wherex,yandzare 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 Graphicsrotate3d. 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 forQubeis available from this link:Qube_osf.m. Theosf,one single file, format is a self-extracting archive that expands into a directory of individual functions.
To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.