I’m trying for many hours to translate a mathematical path (a sin wave) from one coordinate position to another.. but either i’m stupid or something goes wrong.
I tryed this
// Translate
for (int i=0; i < 300; i++) {
coordinatesX[i] = coordinatesX[i] + ( 80 - coordinatesX[i]);
coordinatesY[i] = coordinatesY[i] + (100 - coordinatesY[i]);
}
Where 80 and 100 are the new coordinate position to which i wanna to translate my object.
I tryed this
// Translate
for (int i=0; i < 300; i++) {
coordinatesX[i] = coordinatesX[i] + 80;
coordinatesY[i] = coordinatesY[i] + 100;
}
But all seems to partially work or work only if the wave has some angle ?
I think I was missing some mathematics at school. I’m programming in Java using the AndEngine . May be there are some shortcuts to this elementar function.
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]);
//coordinatesX[i] = coordinatesX[i] + centerX;
//coordinatesY[i] = coordinatesX[i]+centerY;
}
// 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);
}
Here’s an example of how to translate a sine wave. Adapt it according to your needs.