c++ - 点绕某一点的角度

标签 c++ rotation geometry angle

我对从某个点和问题以某个角度旋转一个点做了一些调查:C++: Rotating a vector around a certain point到目前为止我已经想出了以下方法,但它没有给我正确的结果,有人可以找出问题所在吗

const float angle = -90.0;
const float degreePerRadian = 57.2957795;
const float s = sin(angle / degreePerRadian);
const float c = cos(angle / degreePerRadian);
int p1x = 320;
int p1y = 480;
int p2x = 320;
int p2y = 320;

float centerX = (p2x - p1x) / 2 + p1x;
float centerY = (p2y - p1y) / 2 + p1y;
p2x -= centerX;
p2y -= centerY;
double newX = centerX + (p2x * c - p2y * s);
double newY = centerY + (p2x * s + p2y * c);

我得到:newX = 240 和 newY = 400

编辑: 不过我有一架奇怪的飞机

                                |
                                |    ^
                                |    |
                                |
       -------> ^ (320, 480)    |   (y+)
            90° |               |    |
                |               |    |
                |               |
                . (320, 320)    |
                                |
                                |
      --------------------------(0,0)
                <-- (x+) --

如果我想找出点 (320, 480) 的 90 度角,如果线落在左边和右边

事实上,更准确地说,平原是颠倒的(基本上我使用的是 QGraphicsScene,所以左上角是 0,0,右下角是 width(), height()

                (x+) --->
     (0,0) --------------------------
     |
     |
     |      . (320, 320)
     |      |
     |      |
     |      | 90°
     |      . (320, 480)----------
     |
     |
(y+) |
     |
     |

最佳答案

链接中的第 16 行代码不正确。应该是:

double newY = centerY + (p2x * s + p2y * c);

关于c++ - 点绕某一点的角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15107604/

相关文章:

ios - 旋转后 UIView 坐标被交换但 UIWindow 不是?

java - 在 Java 中计算 alpha 形状(凹包)

python - 跨 kd 树的双重递归以查找两组点之间最接近的方法

c++ - 更改 .cpp、.h 文件的 Visual Studio 默认路径

c++ - 将指向成员变量的指针作为参数时出错;为什么?

R:使用 rgl 生成可以在网络浏览器中查看的 3d 可旋转图?

iPhone - 设备转动时禁止 UIView 旋转

math - 查找两个形状之间的仿射变换矩阵(SVG 路径)

c# - 在非托管 cpp dll 中实现 C# 接口(interface)

c++ - 使用字母字符加密/解密 XOR