如果超过45度,为什么旋转不起作用

时间:2012-01-11 10:25:26

标签: java andengine game-physics

我正在尝试在轴上旋转一个波,但不知何故,如果我将传递给sin并且cos值大于45,则波似乎会失真或者函数没有以适当的角度旋转。

...
wave

// ROtate 
for (int i=0; i<300; i++){
    coordinatesX[i] = ((coordinatesX[i] * (float)Math.cos(60)) - (coordinatesY[i] * (float)Math.sin(60))) + coordinatesX[i];
    coordinatesY[i] = (coordinatesX[i] * (float)Math.sin(60)) + (coordinatesY[i] * (float)Math.cos(60)) + coordinatesY[i];
}

这是整个代码:

// define newpath
float[] coordinatesX = new float[300]; 
float[] coordinatesY = new float[300];
// wave
for (int i=0; i<300; i++){
    coordinatesX[i] =  i;
    coordinatesY[i] = (float)(20 * (Math.sin((-0.10 * coordinatesX[i]))));
    System.out.println(coordinatesX[i]);
    System.out.println(coordinatesY[i]);
}


// ROtate 
for (int i=0; i<300; i++){
    coordinatesX[i] = ((coordinatesX[i] * (float)Math.cos(-10)) - (coordinatesY[i] * (float)Math.sin(-10))) + coordinatesX[i];
    coordinatesY[i] = (coordinatesX[i] * (float)Math.sin(-10)) + (coordinatesY[i] * (float)Math.cos(-10)) + coordinatesY[i];
}

// Translate 
for (int i=0; i < 300; i++) {
    coordinatesX[i] = coordinatesX[i]+ (200);
    coordinatesY[i] = coordinatesY[i] + (300);
}

1 个答案:

答案 0 :(得分:5)

从你的代码中不清楚你到底做了什么,但你提到45度

Math.sin()Math.cos()使用弧度 http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html