2D Euclidean vector rotations(2D 欧几里得矢量旋转)
问题描述
我有一个欧几里得向量 a
位于坐标 (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?
推荐答案
你应该从函数中删除变量:
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 欧几里得矢量旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:2D 欧几里得矢量旋转
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01