[ 本帖最后由 hubo5563 于 2014-5-5 11:53 编辑 ]
转动操作的块轮换我也是手工输入的,魔方复杂时数据很多,例如百慕大五角24面体,24个转动面,每个面有11个块,我用一个数组表示,这些数据也是手工输入的:
private static final int[][] PiceLunHuan=
{ //24个面转动360/11度角的各个块的位置轮换
{37,92, 36, 93,38, 94,39, 95,25, 80,24}, //0
{24,80, 25, 81,26, 82,27, 83,28, 84,29}, //1
{29,84, 28, 85,30, 86,31, 87,32, 88,33}, //2
{33,88, 32, 89,34, 90,35, 91,36, 92,37}, //3
{54,113,53,117,56,116,57,115,58,114,59}, //4
{59,114,58,118,38, 93,36, 91,35,109,60}, //5
{60,109,35, 90,34,108,50,107,49,110,55}, //6
{55,110,49,106,48,111,52,112,53,113,54}, //7
{65,123,64,127,71,128,72,129,73,131,74}, //8
{74,131,73,130,26, 81,25, 95,39,125,67}, //9
{67,125,39, 94,38,118,58,115,57,124,66}, //10
{66,124,57,116,56,121,63,122,64,123,65}, //11
{76,139,75,134,44, 99,41, 97,40,137,79}, //12
{79,137,40, 96,30, 85,28, 83,27,138,78}, //13
{78,138,27, 82,26,130,73,129,72,132,77}, //14
{77,132,72,128,71,126,70,133,75,139,76}, //15
{47,102,46,105,48,106,49,107,50,103,51}, //16
{51,103,50,108,34, 89,32, 87,31,104,43}, //17
{43,104,31, 86,30, 96,40, 97,41, 98,42}, //18
{42, 98,41, 99,44,100,45,101,46,102,47}, //19
{69,135,70,126,71,127,64,122,63,120,62}, //20
{62,120,63,121,56,117,53,112,52,119,61}, //21
{61,119,52,111,48,105,46,101,45,136,68}, //22
{68,136,45,100,44,134,75,133,70,135,69} //23
};
里面都是块的顺序号。
处理转动群的程序简单:
void lunhuancz(int n)
{ //正向转动一层后的块轮换操作
int i,k;
k=CubeX[PiceLunHuan[n][0]];
for(i=1;i<11;i++)
{
CubeX[PiceLunHuan[n][i-1]]=CubeX[PiceLunHuan[n][i] ];
};
CubeX[PiceLunHuan[n][10]]=k;
CubeTurn[n]=(CubeTurn[n]+1) % 11;
};
void lunhuanczf(int n)
{ //反向转动一层后的块轮换操作
int i,k;
k=CubeX[PiceLunHuan[n][10]];
for(i=10;i>0;i--)
{
CubeX[PiceLunHuan[n][i]]=CubeX[PiceLunHuan[n][i-1] ];
};
CubeX[PiceLunHuan[n][0]]=k;
CubeTurn[n]=(CubeTurn[n]+10) % 11;
};
CubeTurn[]是一个记录每个面的转动角度数组,用来判断相邻面是否可以转动的,初始都是根据面编码程序自动生成的。
CubeX是个数组,记录转动后魔方各个位置的块序号,初始是顺序的。
n是转动的面号,每次转动根据转动方向执行上面对应的轮换程序。
至于块的方向,都反映在坐标里了,不需要记录。
每次转动时只转动转面牵涉到的块:
for(i=0;i<11;i++)
{
zhuandong(Cube[CubeX[PiceLunHuan[n][i]]]); //面上的棱块和角块
};
zhuandong(Cube[n]); //中心块
zhuandong()
就是对块里的每个3D点坐标变换。Cube[]是Piece 数组。
那些数据是根据下面的图输入的,图中粉色数是中心块号,蓝色数是棱块和角块号,需要把图中数加上24:因为块数组前24个是中心块。
|