【发布时间】:2013-02-27 08:45:28
【问题描述】:
我已经对从某个点和问题中以某个角度旋转一个点进行了一些调查: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,右下角是宽度(),高度()
(x+) --->
(0,0) --------------------------
|
|
| . (320, 320)
| |
| |
| | 90°
| . (320, 480)----------
|
|
(y+) |
|
|
【问题讨论】:
-
您是否使用弧度值?据我所知,大多数 sin/cos 函数都期望它们以弧度表示。
-
@Losiowaty 好的,如果我将它从弧度更改为度数,我会得到 (-160, 2.87183e-07)
-
不,弧度很好 :) 这只是我想到的第一件事。
-
没有帮助,pastebin.com/LUFyjCae 这是代码
标签: c++ rotation geometry angle