【发布时间】:2010-07-02 00:57:37
【问题描述】:
以下任何一种方法是否使用正确的数学方法来旋转一个点?如果有,哪一个是正确的?
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,或者实际上没有返回任何东西。
-
@Brian Hooper:+1 指出有意义的变量名的好处;)
标签: c# c++ geometry trigonometry