簡體   English   中英

點圍繞某點的角度

[英]Angle of point around certain point

我對從某個點到某個角度以及從某個角度以某個角度旋轉一個點進行了一些調查: C ++:到目前為止,我一直想出一個圍繞某個點旋轉矢量的方法,但是它沒有給我正確的結果,有人可以識別一下嗎問題

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM