簡體   English   中英

計算旋轉(或旋轉)

[英]Calculating rotation(or spin)

我在 canvas 上查看 W3 的參考資料,在一個示例中,他們創建了一個紅色塊並進行以下計算以確定其 x、y:

this.angle += this.moveAngle * Math.PI / 180;
this.x += this.speed * Math.sin(this.angle);
this.y -= this.speed * Math.cos(this.angle);

整片

sin 和 cos 在改變塊的 x,y position 中起什么作用?

在該示例中,object 的速度與角度有關。
只需嘗試刪除它,您就會看到會發生什么。

代替:

this.x += this.speed * Math.sin(this.angle);
this.y -= this.speed * Math.cos(this.angle);

做吧:

this.x += this.speed;
this.y -= this.speed;

您的 object 將不再沿角度方向移動。
這只是一個簡單實用的解釋。


但是你應該更多地閱讀三角函數:
https://en.wikipedia.org/wiki/Trigonometry

可汗學院有一個課程:
https://www.khanacademy.org/math/trigonometry

暫無
暫無

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

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