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

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

问题描述

执行下列任一下面的方法用于旋转点的正确数学?如果是这样,哪一个是正确的?

  POINT rotate_point(浮点CX,CY浮动,浮动角度,点P)
{
  浮S =罪(角);
  浮C = COS(角度);  //回翻译点原点:
  p.x - = CX;
  p.y - = CY;  // 哪一个是对的:
  // 这个?
  浮xnew = p.x * C - p.y * S;
  浮ynew = p.x * S + p.y * C;
  // 或这个?
  浮xnew = p.x * C + p.y * S;
  浮ynew = -p.x * S + p.y * C;  //翻译点回:
  p.x = xnew + CX;
  p.y = ynew + CY;
}


解决方案

这要看你如何定义角度。如果它是逆时针方向测量(这是数学约定),则正确的旋转是您的第一个:

  //这个?
浮xnew = p.x * C - p.y * S;
浮ynew = p.x * S + p.y * C;

但如果是顺时针测量,然后第二个是正确的:

  //或那样吗?
浮xnew = p.x * C + p.y * S;
浮ynew = -p.x * S + p.y * C;

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;
}

解决方案

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天全站免登陆