Jos*_*hua 15 c# c++ geometry trigonometry
以下任何一种方法都使用正确的数学来旋转一个点吗?如果是这样,哪一个是正确的?
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;
}
Run Code Online (Sandbox Code Playgroud)
Bet*_*eta 23
这取决于你如何定义angle.如果它是逆时针测量的(这是数学约定)那么正确的旋转是你的第一个:
// This?
float xnew = p.x * c - p.y * s;
float ynew = p.x * s + p.y * c;
Run Code Online (Sandbox Code Playgroud)
但如果顺时针测量,那么第二个是正确的:
// Or This?
float xnew = p.x * c + p.y * s;
float ynew = -p.x * s + p.y * c;
Run Code Online (Sandbox Code Playgroud)