我正在尝试在轴上旋转一个波,但不知何故,如果我将传递给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);
}
答案 0 :(得分:5)
从你的代码中不清楚你到底做了什么,但你提到45度
Math.sin()
和Math.cos()
使用弧度
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html