本文介绍了围绕原点旋转一个点的正确三角法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
以下任何一种方法是否使用正确的数学方法来旋转一个点?如果有,哪一个是正确的?
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;
这篇关于围绕原点旋转一个点的正确三角法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!