I'm writing a sprite like simulation where I need to move a label with an image in a circular path. I have 4 starting points; west, north, east and south. The label should move in a clockwise manner.
This is what I wrote and it works well, except for the fact that north and south positions circle counter-clockwise. The reason is that, I've used a separate trig formula to handle directions 2 and 4.
int xstart = 450
int ystart = 325;
int h = 0;
double theta = -0.1047;
for (int p = 0;; p++)
{
int xocir = xstart;
int yocir = ystart;
int pocir = 0; // perpendicular and base of outer circle
int bocir = 0;
if (direction == 1)//west - clockwise
{
pocir = (int) (Math.cos(theta) * (h + 300));
bocir = (int) (Math.sin(theta) * (h + 300));
}
else if (direction == 2)//north - counter-clockwise
{
pocir = (int) (Math.sin(theta) * (h + 300));//reversed sin,cos
bocir = (int) (Math.cos(theta) * (h + 300));
}
else if (direction == 3)//east - clockwise
{
pocir = (int) (Math.cos(theta) * (h - 300));
bocir = (int) (Math.sin(theta) * (h - 300));
}
else if (direction == 4)//south - counter-clockwise
{
pocir = (int) (Math.sin(theta) * (h - 300));
bocir = (int) (Math.cos(theta) * (h - 300));
}
xocir = xocir - pocir;
yocir = yocir - bocir;
theta = theta - 0.005;
setBounds(xocir, yocir, 65, 65);
}
Is there a more efficient way to tackle this? Maybe a simpler trig method. And what can I do to make sure all motion is clockwise?