我正在尝试在轴上旋转波浪,但是以某种方式,如果我传递到正弦值并将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);
}

最佳答案

您的代码尚不清楚您到底要做什么,但您提到了45度

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

10-05 21:22