## for Rubik's Cube Simulation by MC3D

### by David Vanderschel

Different folks have different ways of talking about the puzzle. To establish my way of talking about it in this context, I will rattle on here a bit, introducing and using the words I like.

### Cubies

Conceptually, the puzzle consists of a 3x3x3 pile of cubies. A cubie is a 1x1x1 volume of 3-space - a unit cube in 3-space. The resulting 3x3x3 volume is bounded by 6 surfaces called faces. These 6 faces have distinct positions and orientations in 3-space. There are 6 such orientations. To distinguish between a face of the complete puzzle and a face of an individual cubie, an instance of the latter is referred to as a facelet when there is any chance of confusion.

Cubie positions are described here by the coordinates of their centers. The three coordinate axes are conventionally referred to as x, y, and z, respectively. The 27 cubies are grouped around the origin in 3-space so that each of the three coordinates of a cubie must be one of -1, 0 , or +1.

```
The cubie with all coordinates zero is called the      heart  cubie.
Cubies with 2 zero coordinates (1 non-zero) are called face   cubies.
Cubies with 1 zero coordinate  (2 non-zero) are called edge   cubies.
Cubies whose 3 coordinates are all non-zero are called corner cubies.
```

### Directions

```    Directions along the x axis are referred to as Left  and Right: L R
Directions along the y axis are referred to as Front and Back:  F B
Directions along the z axis are referred to as Down  and Up:    D U
```

The two single characters at the ends of the above lines are used extensively to name things and describe directions. In each case, the first mentioned character is that associated with the negative direction of the associated axis. The characters are often concatenated in the BFUDLR order, and there is a commonly used notation for describing cube moves based on these characters.

### Stickers

For each axis for which the coordinate of a cubie is not zero, the cubie has an exposed facelet. Each such facelet is marked by the attachment of a colored sticker. Conceptually a sticker is a 2D square (1x1) having the same color throughout the corresponding area. A sticker is considered to have the same orientation and position in 3-space as the facelet to which it is stuck.

```    cubie    number    colors     stickers
type   of type   per cubie    on type

corner     8          3          24
edge      12          2          24
face       6          1           6
heart      1          0           0

Total     27                     54 stickers   (9x6)
```

When the puzzle is in its initial or start position, we say that all the cubies are home. When all the cubies are home, all stickers facing in the same direction (i.e., on the same face of the cube) have the same color. The name used for that color is the character associated with that direction. E.g., the D-face of the cube has 9 stickers of color D, one on each of 9 cubies with z coordinate -1.

The single sticker on a face cubie is called a face sticker. Thus reference to a face sticker implies that we are talking about the sticker on a face cubie. The face sticker for a given face is the sticker on the face cubie at the middle of the given face.

### Naming Conventions

Upper case versions of the 6 direction-indicating characters are used to name things. Thus, for example, we may refer to the B-face of the cube. It is the one which faces in the positive y-direction when the cube is intialized and "B" is used to name the color of its face sticker and the corresponding slice. Lower case versions of the 6 characters are used to indicate directions. E.g., in the Model Coordinate System, the b-direction is the positive y-direction. It is often convenient to think of these direction indicators as corresponding to unit vectors along their corresponding axes. (What is not typical here is that we have separate names for positive and negative facing such vectors on each axis.)

### Slices

A slice is a 1x3x3 'pile' of (9) cubies. The axis for which the 'pile' has thickness 1 (not necessarily x) is referred to as the axis of the slice. The slice is said to be parallel to the 2D plane perpendicular to the axis of the slice. Slices with the same axis are said to be parallel to one another. A slice with axis z, say, is referred to as a "z-slice". All cubies in a slice have the same coordinate value for the slice axis. If that coordinate value is zero, the slice is a center slice. Otherwise, the slice is an external slice. The cube has 9 slices - three for each of the 3 axes. Each cubie belongs to 3 slices and belongs to as many external slices as it has stickers (or exposed facelets). There is a one-to-one correspondence between external slices and cube faces and they are similarly named. E.g., in initial position, the 9 R-colored stickers of the R-face are all stuck on the r-facing facelets of the 9 cubies in the R-slice. Upper case versions of the axis names, XYZ, are used to name the corresponding center slices.

When we operate the puzzle we are turning slices. But, because of the close relationship between slices and faces, we will also refer to turning a face in a manner synonymous to turning the corresponding external slice. It just must be understood that there are some other stickers, not actually in the face, which turn with it.

### Coordinate Systems

The coordinate system with respect to which the 3D model of the cube is described is called the Model Coordinate System which is abbreviated with the acronym MCS. It is a fixed spatial coordinate system. For rendering purposes, the eyepoint is placed somewhere within the MCS. Because the eyepoint can be anywhere and the display can be rotated, there is no standard alignment of the MCS relative to the display. The MCS orientation tattle in the lower left illustrates how the MCS maps to the display.

The program allows center slice and whole cube twists, so the orientation of the cube can change relative to the MCS. I.e., there is no guarantee that a particular face sticker will continue to face in the direction for which its color is named. E.g., after turning the horizontal center slice (a z-slice) the B-face could be pointing in the r-direction.

For theoretical purposes, there is a more convenient coordinate system which ignores reorientations of the cube in the MCS. This called the Face Coordinate System or FCS. In the FCS, the R-face always faces in the positive x-direction, etc. I.e., directions are determined by the current positions of the face stickers. When you reorient the cube, the FCS turns with it. The FCS tattle in the lower right illustrates how the FCS maps to the display. It will differ from that for the MCS only if you perform center slice twists or whole cube twists.

### Perspective Projection

As an example of 3D to 2D perspective projection, let us use as our projection plane the hyperplane in 3-space for which the z-coordinate is zero. I.e., points of the form `(x, y, 0)` for all values of x and y. You can think of this as a 2-dimensional xy-plane embedded in 3D. In order to make a projection, you must be looking from some place. Let us position our eyepoint at a distance `d` from the origin on the positive z-axis. (The first 3 built-in configurations for the program all have the eyepoint on the positive z-axis.) I.e., let `E = (0, 0, d)` be our eyepoint. Let us project the general point `P = (x, y, z)`. This is done by casting a ray from the eyepoint through `P`. Where that ray intersects the projection plane is the projected image of `P`. The ray can be parameterized as

```    { E + t × (P-E) | t>=0 }.
```

I.e., the set of points of the form `( t × x, t × y, d + t × (z-d) )` for nonnegative `t`. The value of the parameter `t` for which the z-component is zero is `t = d/(d-z)`. Thus the perspective projection maps `P` to the point `d/(d-z) × (x, y, 0)`. Now `(x, y, 0)` is the orthographic projection of `P` along the z-axis. Concentrating on the image itself as being in a 2D space, we can think of the perspective transformation in two steps.

```    Orthographic Projection:  (x, y, z)  &rarr  (x, y)
Scaling by d/(d-z):       (x, y)     &rarr  d/(d-z) × (x, y)
```

We see that the result of using perspective projection is to scale, relative to the origin, the orthographic projection by the factor `d/(d-z)`. If we are talking about projecting sets of points which describe objects, we see that objects closer to us than the projection plane project larger while those farther project smaller.

Note the `d-z` in the denominator. That implies that, if the z-coordinate of something we are trying to project approaches `d`, we are in trouble. We really do not want to try to project things that do not lie in front of the eyepoint as we are looking toward the origin. As long as `z` is less than `d`, the projection makes sense. We can project points with arbitrarily large `z` magnitude in the negative direction. As `z` tends toward minus infinity the scale factor becomes progressively smaller. If you think in terms of projecting something that is moving away from the eyepoint in the negative z-direction, we see that its image will become progressively smaller and move towards the origin. Thus the origin of the projection plane is referred to as the "vanishing point" for lines parallel to the z-axis.

The program does use a projection plane which passes through the origin of 3-space. However, it does not require the eyepoint to be on any axis. The projection plane is just required to be perpendicular to the direction from the origin to the eyepoint. Assuming still a distance `d` from the origin for the eyepoint, instead of `z`, the number we subtract from `d` in the denominator is the distance of a projected point from the projection plane, with that distance regarded as negative when the point is on the opposite side of the projection plane from the eyepoint. The value of `d` is what the program calls the 3D Viewing Distance. It imposes a minimum value on `d` which assures that no portion of the cube can reach a position for which the z-coordinate reaches or exceeds `d`. (When you use that minimum value, the perspective effect is very exaggerated and the picture looks quite weird.)

Since the cube extends to either side of the projection plane, some features grow while others shrink. Since we are normally looking from sufficiently far away that the maximum difference between the growth and shrink factors is moderate, we can say, roughly speaking, that units in the projection plane correspond to those of the MCS.