簡體   English   中英

使用 atan2() 返回的角度圍繞另一個點旋轉一個點

[英]Rotate a point around another point using the angle returned by atan2()

我有一個旋轉角度:

var dx = this.mouseX - this.startX;
var dy = this.mouseY - this.startY;

_this.rotation = Math.atan2(dy, dx);

而且我知道我的樞軸點(圖像的中心):

var pivotX = this.x + (this.imageWidth / 2);
var pivotY = this.y + (this.imageHeight / 2);

現在我有另一點:

var rightX = 600;
var rightY = 400;

如何使用我從atan2()函數獲得的角度圍繞我的樞軸點旋轉這個點?

要將點 {x, y} 圍繞原點 {0, 0} 旋轉給定的弧度角,請執行以下數學運算:

new_x_point = old_x_point * cos(Angle) - old_y_point * sin(Angle);
new_y_point = old_y_point * cos(Angle) + old_x_point * sin(Angle);

現在,如果原點或樞軸點不是 {0, 0},那么您需要先從原點的坐標中減去要旋轉的點,然后在該點上進行旋轉,然后添加偏移量旋轉后的點返回,以便將其平移回其原始位置。

暫無
暫無

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

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