[Contents] [TitleIndex] [WordIndex

1. Rubik's Cube

1.1. Introduction

Scilab allows to print Rubik's cube in 3D. In this page, we show how Pierre Chevalier's script performs to do this.

1.2. Sample views

The first part of the script in attachment uses the plot3d function to print a simple 3D cube. It uses the "hidden3d" option so that hidden layers are not shown.

cube1.png

The second part of the script defines the function:

plotcube(position, couleurs)

which plots a Rubik's cube, where "position" is a 3x1 matrix of doubles (the [x,y,z] location of the center of the cube) and "couleurs" is a 6x1 matrix of strings containing the colors of the faces of the cube.

The next function is:

AfficheRubix(ObjetRubix)

which prints the 27 elementary cubes of Rubik's cube. The function:

[ObjetRubix]=CreationRubix()

creates a list of 27 items, where each item represents an elementary cube.

When we execute this script, we get the following figure.

cube2.png

With the rotating feature of the graphics window, we can move the cube as we wish.

cube3.png

1.3. The script

1.4. The next step

The missing script solves the rubik's cube in Scilab, and prints the resulting moves. This involves creating the appropriate data structures and algorithms. The basic data structure may be a 9x12 matrix representing the "unfolded" cube, where each entry represents a cube:

      x x x   
      x x x   
      x x x   
x x x x x x x x x
x x x x x x x x x
x x x x x x x x x
      x x x   
      x x x   
      x x x   
      x x x   
      x x x   
      x x x   

Depending on the number of characters that can be stored in Scilab's console, the transpose might be more convenient.

It is straightforward to number the x, so that each cube is uniquely defined. The basic cube moves "R", "L", "U", "D", "F", "B" (clockwise, twice and counter-clockwise) can then be converted into an update of this matrix. From there, we could apply the classical algorithms to solve the cube. This is the approach used in "Rubik's, Heuristic", Mubbasir. T. Kapadia, D.J Sanghvi, http://www.seas.upenn.edu/~mubbasir/pdfs/rubiks-heuristic.pdf.

Once done, this set of functions could be used to solve a number of interesting questions.

1.5. Reference


2022-09-08 09:27