以下任何一种方法是否使用正确的数学方法来旋转一个点?如果有,哪一个是正确的?
Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct?
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;
}
这取决于你如何定义angle
.如果它是逆时针测量的(这是数学惯例),那么正确的旋转是你的第一个:
It depends on how you define angle
. If it is measured counterclockwise (which is the mathematical convention) then the correct rotation is your first one:
// This?
float xnew = p.x * c - p.y * s;
float ynew = p.x * s + p.y * c;
但如果是顺时针测量,那么第二个是正确的:
But if it is measured clockwise, then the second is correct:
// Or This?
float xnew = p.x * c + p.y * s;
float ynew = -p.x * s + p.y * c;
这篇关于围绕原点旋转一个点的正确三角法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!