这是我正在使用的代码。
#define ANGLETORADIANS 0.017453292519943295769236907684886f // PI / 180
#define RADIANSTOANGLE 57.295779513082320876798154814105f // 180 / PI
rotation = rotation *ANGLETORADIANS;
cosRotation = cos(rotation);
sinRotation = sin(rotation);
for(int i = 0; i < 3; i++)
{
px[i] = (vec[i].x + centerX) * (cosRotation - (vec[i].y + centerY)) * sinRotation;
py[i] = (vec[i].x + centerX) * (sinRotation + (vec[i].y + centerY)) * cosRotation;
printf("num: %i, px: %f, py: %f\n", i, px[i], py[i]);
}
到目前为止它接缝我的Y值正在被翻转..说我输入X = 1和Y = 1的值,旋转45度你应该看到x = 0和y = 1.25 ish但我得到x = 0 y = -1.25。
此外,我的90度旋转总是返回x = 0和y = 0.
p.s我知道我只是把我的价值观集中在一起,而不是把它们放回原处。我不需要把它们放回去,因为我需要知道的是我现在所获得的价值。
答案 0 :(得分:2)
您的支架位置对我来说不合适。我希望:
px[i] = (vec[i].x + centerX) * cosRotation - (vec[i].y + centerY) * sinRotation;
py[i] = (vec[i].x + centerX) * sinRotation + (vec[i].y + centerY) * cosRotation;
答案 1 :(得分:1)
你的括号错了。它应该是
px[i] = ((vec[i].x + centerX) * cosRotation) - ((vec[i].y + centerY) * sinRotation);
py[i] = ((vec[i].x + centerX) * sinRotation) + ((vec[i].y + centerY) * cosRotation);
代替