|
CubeTwister 2.0alpha142 2012-02-11 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectch.randelshofer.rubik.AbstractCube
ch.randelshofer.rubik.RubiksCube
public class RubiksCube
Represents the state of a 3-times sliced cube (Rubik's Cube) by the location and orientation of its parts.
A Rubik's Cube has 8 corner parts, 12 edge parts, 6 face parts and one center part. The parts divide each face of the cube into 3 x 3 layers.
Corner parts
The following diagram shows the initial orientations and locations of the corner parts:
+---+---+---+
|4.0| |2.0|
+--- ---+
| 1 |
+--- ---+
|6.0| |0.0|
+---+---+---+---+---+---+---+---+---+---+---+---+
|4.1| |6.2|6.1| |0.2|0.1| |2.2|2.1| |4.2|
+--- ---+--- ---+--- +---+--- ---+
| 3 | 2 | 0 | 5 |
+--- ---+--- ---+--- +---+--- ---+
|5.2| |7.1|7.2| |1.1|1.2| |3.1|3.2| |5.1|
+---+---+---+---+---+---+---+---+---+---+---+---+
|7.0| |1.0|
+--- ---+
| 4 |
+--- ---+
|5.0| |3.0|
+---+---+---+
Edge parts
The following diagram shows the initial orientations and locations of the edge parts:
+---+---+---+
| |3.1| |
+--- --- ---+
|6.0| 1 |0.0|
+--- --- ---+
| |9.1| |
+---+---+---+---+---+---+---+---+---+---+---+---+
| |6.1| | |9.0| | |0.1| | |3.0| |
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
|7.0| 3 10.0|10.1 2 |1.1|1.0| 0 |4.0|4.1| 5 |7.1|
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
| |8.1| | |11.0 | |2.1| | |5.0| |
+---+---+---+---+---+---+---+---+---+---+---+---+
| |11.1 |
+--- --- ---+
|8.0| 4 |2.0|
+--- --- ---+
| |5.1| |
+---+---+---+
Side parts
The following diagram shows the initial orientation and location of the face parts:
+------------+
| .1 |
| --- |
| .0| 1 |.2 |
| --- |
| .3 |
+-----------+------------+-----------+-----------+
| .0 | .2 | .3 | .1 |
| --- | --- | --- | --- |
| .3| 3 |.1 | .1| 2 |.3 | .2| 0 |.0 | .0| 5 |.2 |
| --- | --- | --- | --- |
| .2 | .0 | .1 | .3 |
+-----------+------------+-----------+-----------+
| .0 |
| --- |
| .3| 4 |.1 |
| --- |
| .2 |
+------------+
For more information about the location and orientation of the parts see
AbstractCube.
Stickers
The following diagram shows the arrangement of stickers on a Rubik's Cube: The number before the comma is the first dimension (faces), the number after the comma is the second dimension (stickers).
+---+---+---+
|1,0|1,1|1,2|
+--- --- ---+
|1,3|1,4|1,5|
+--- --- ---+
|1,6|1,7|1,8|
+---+---+---+---+---+---+---+---+---+---+---+---+
|3,0|3,1|3,2|2,0|2,1|2,2|0,0|0,1|0,2|5,0|5,1|5,2|
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
|3,3|3,4|3,5|2,3|2,4|2,5|0,3|0,4|0,5|5,3|5,4|5,5|
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
|3,6|3,7|3,8|2,6|2,7|2,8|0,0|0,1|0,2|5,0|5,1|5,2|
+---+---+---+---+---+---+---+---+---+---+---+---+
|4,0|4,1|4,2|
+--- --- ---+
|4,3|4,4|4,5|
+--- --- ---+
|4,6|4,7|4,8|
+---+---+---+
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class ch.randelshofer.rubik.AbstractCube |
|---|
AbstractCube.TransformType |
| Field Summary | |
|---|---|
protected static int[][] |
CORNER_TRANSLATION
This is used for mapping corner part locations and orientations to/from sticker positions on the cube. |
protected static int[][] |
EDGE_TRANSLATION
This is used for mapping edge part locations and orientations to/from sticker positions on the cube. |
static int |
NUMBER_OF_EDGE_PARTS
Holds the number of edge parts, which is 12. |
static int |
NUMBER_OF_SIDE_PARTS
Holds the number of face parts, which is 6. |
protected static int[][] |
SIDE_TRANSLATION
This is used for mapping face part locations to/from sticker positions on the cube. |
| Fields inherited from class ch.randelshofer.rubik.AbstractCube |
|---|
CENTER_PART, CENTER_TO_SIDE_MAP, CORNER_PART, CORNER_SWIPE_TABLE, CORNER_TO_FACE_MAP, cornerLoc, cornerOrient, EDGE_PART, EDGE_TO_ANGLE_MAP, EDGE_TO_AXIS_MAP, EDGE_TO_FACE_MAP, edgeLoc, edgeOrient, layerCount, NUMBER_OF_CORNER_PARTS, SIDE_PART, sideLoc, sideOrient, transformAngle, transformAxis, transformMask, transformType |
| Constructor Summary | |
|---|---|
RubiksCube()
Creates a new instance. |
|
| Method Summary | |
|---|---|
int |
getPartLayerMask(int part,
int orientation)
Returns the current layer mask on which the orientation of the part lies. |
int |
getPartSwipeAngle(int part,
int orientation,
int swipeDirection)
Returns the angle on which the orientation of the part can be swiped into the specified direction. |
int |
getPartSwipeAxis(int part,
int orientation,
int swipeDirection)
Returns the axis on which the orientation of the part can be swiped into the specified direction. |
int |
getPartSwipeLayerMask(int part,
int orientation,
int swipeDirection)
Returns the layer mask on which the orientation of the part can be swiped into the specified direction. |
void |
setToStickers(int[][] stickers)
Sets the cube to a state where the faces of the parts map to the provided stickers array. |
int[][] |
toStickers()
Returns an array of stickers which reflect the current state of the cube. |
void |
transform0(int axis,
int layerMask,
int angle)
Transforms the cube and fires a cubeTwisted event. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int NUMBER_OF_SIDE_PARTS
public static final int NUMBER_OF_EDGE_PARTS
protected static final int[][] SIDE_TRANSLATION
toStickers()protected static final int[][] EDGE_TRANSLATION
Description:
edge orientation 0: face index, sticker index.
edge orientation 1: face index, sticker index.
toStickers()protected static final int[][] CORNER_TRANSLATION
Description:
corner orientation 0, face index, corner orientation 1, face index, corner orientation 2, face index
XXX - Move this into RubiksCube class.
toStickers()| Constructor Detail |
|---|
public RubiksCube()
| Method Detail |
|---|
public int getPartLayerMask(int part,
int orientation)
getPartLayerMask in interface CubegetPartLayerMask in class AbstractCube
public int getPartSwipeAxis(int part,
int orientation,
int swipeDirection)
Cube
part - The part index.orientation - The orientation of the part where swiping is performed.swipeDirection - The direction of the swipe. 0=up,1=right,2=down,4=left.
public int getPartSwipeLayerMask(int part,
int orientation,
int swipeDirection)
Cube
part - The part index.orientation - The orientation of the part where swiping is performed.swipeDirection - The direction of the swipe. 0=up,1=right,2=down,4=left.
public int getPartSwipeAngle(int part,
int orientation,
int swipeDirection)
Cube
part - The part index.orientation - The orientation of the part where swiping is performed.swipeDirection - The direction of the swipe. 0=up,1=right,2=down,4=left.
public void transform0(int axis,
int layerMask,
int angle)
transform0 in class AbstractCubeaxis - 0=x, 1=y, 2=z axis.layerMask - A bitmask specifying the layers to be transformed.
The size of the layer mask depends on the value returned by
getLayerCount(axis). The layer mask has the
following meaning:
7=rotate the whole cube;angle - positive values=clockwise rotationAbstractCube.getLayerCount()public int[][] toStickers()
The following diagram shows the indices of the array. The number before the comma is the first dimension (faces), the number after the comma is the second dimension (stickers).
The values of the array elements is the face index: 0..5.
+---+---+---+
|1,0|1,1|1,2|
+--- --- ---+
|1,3|1,4|1,5|
+--- --- ---+
|1,6|1,7|1,8|
+---+---+---+---+---+---+---+---+---+---+---+---+
|3,0|3,1|3,2|2,0|2,1|2,2|0,0|0,1|0,2|5,0|5,1|5,2|
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
|3,3|3,4|3,5|2,3|2,4|2,5|0,3|0,4|0,5|5,3|5,4|5,5|
+--- --- ---+--- --- ---+--- --- ---+--- --- ---+
|3,6|3,7|3,8|2,6|2,7|2,8|0,0|0,1|0,2|5,0|5,1|5,2|
+---+---+---+---+---+---+---+---+---+---+---+---+
|4,0|4,1|4,2|
+--- --- ---+
|4,3|4,4|4,5|
+--- --- ---+
|4,6|4,7|4,8|
+---+---+---+
Cube.setToStickers(int[][])public void setToStickers(int[][] stickers)
Cube
stickers - Sticker array to be reused. The method creates a new
array if this parameter is null.
|
(c) Werner Randelshofer. All rights reserved. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||