绕原点旋转点的适当三角学
以下任一方法是否使用正确的数学来旋转点?如果是这样,哪一个是正确的?
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自维基百科
要使用矩阵执行旋转,点 (x, y )要旋转的被写为向量,然后乘以根据角度 θ 计算的矩阵,如下所示:
其中 (x′, y′) 是旋转后点的坐标,公式对于 x′ 和 y′ 可以看作
From Wikipedia
To carry out a rotation using matrices the point (x, y) to be rotated is written as a vector, then multiplied by a matrix calculated from the angle, θ, like so:
where (x′, y′) are the co-ordinates of the point after rotation, and the formulae for x′ and y′ can be seen to be
这取决于您如何定义
角度
。如果是逆时针测量(这是数学约定),那么正确的旋转是第一个:但如果是顺时针测量,那么第二个是正确的:
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:But if it is measured clockwise, then the second is correct:
这是从我自己的矢量库中提取的..
This is extracted from my own vector library..