Question

I'm trying to rotate a wave on the axis but somehow if I'll pass to the sin and cos a value more than 45 the wave seems to get distortion or the function is not rotated with the proper angle.

...
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];
}

This is the whole code:

// 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);
}
Was it helpful?

Solution

it's unclear from your code what you do exactly, but you mention 45 degrees

Math.sin() and Math.cos() work with radians http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Math.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top