以下两种方法中的哪一种使用正确的数学来旋转点?如果是这样,哪一个是正确的?适当的三角法旋转原点的位置
POINT rotate_point(float cx,float cy,float angle,POINT p)
{
float s = sin(angle);
float c = cos(angle);
// translate point back to origin:
p.x -= cx;
p.y -= cy;
// Which One Is Correct:
// This?
float xnew = p.x * c - p.y * s;
float ynew = p.x * s + p.y * c;
// Or This?
float xnew = p.x * c + p.y * s;
float ynew = -p.x * s + p.y * c;
// translate point back:
p.x = xnew + cx;
p.y = ynew + cy;
}
我不很明白。什么是cx和cy?另外,你已经声明了你的POINT类型的函数,但是它不返回一个POINT,或者其他任何东西。 – 2010-07-02 01:09:06
@Brian Hooper:+1用于指出有意义的变量名称的好处;) – Cogwheel 2010-07-02 04:43:02