围绕原点旋转一个点的正确三角法 [英] Proper Trigonometry For Rotating A Point Around The Origin

查看:26
本文介绍了围绕原点旋转一个点的正确三角法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下任何一种方法是否使用正确的数学方法来旋转一个点?如果有,哪一个是正确的?

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;

这篇关于围绕原点旋转一个点的正确三角法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆