2D欧几里德矢量旋转 [英] 2D Euclidean vector rotations

查看:218
本文介绍了2D欧几里德矢量旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个坐标为(0,1)的欧氏向量 a
我想围绕原点将旋转90度(顺时针):(0,0)

I have a euclidean vector a sitting at the coordinates (0, 1). I want to rotate a by 90 degrees (clockwise) around the origin: (0, 0).

如果我正确理解这应该如何工作,旋转后的结果(x,y)坐标应该(1, 0)
如果我将它旋转45度(仍然顺时针),我会预期结果坐标为(0.707,0.707)

If I have a proper understanding of how this should work, the resultant (x, y) coordinates after the rotation should be (1, 0). If I were to rotate it by 45 degrees (still clockwise) instead, I would have expected the resultant coordinates to be (0.707, 0.707).

theta = deg2rad(angle);

cs = cos(theta);
sn = sin(theta);

x = x * cs - y * sn;
y = x * sn + y * cs;

使用上述代码,使用 angle 值为90.0度,则结果坐标为:( - 1,1)
我很害怕。
以下链接中的示例代表了上面显示的相同公式?

Using the above code, with an angle value of 90.0 degrees, the resultant coordinates are: (-1, 1). And I am so damn confused. The examples seen in the following links represent the same formula shown above surely?

我做错了什么?
或者我误解了一个向量是如何旋转的:

What have I done wrong? Or have I misunderstood how a vector is to be rotated?

推荐答案

你应该从函数中删除vars:

you should remove the vars from the function:

x = x * cs - y * sn; // now x is something different than original vector x
y = x * sn + y * cs;

创建新坐标,避免在到达第二行之前计算x:

create new coordinates becomes, to avoid calculation of x before it reaches the second line:

px = x * cs - y * sn; 
py = x * sn + y * cs;

这篇关于2D欧几里德矢量旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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