arctan2()


Game Maker Language リファレンス > 組み込み関数 用途別 > 数値計算・文字列・日付/時間 > arctan2

arctan2()

  • 対応:5.3A 6.0 6.1A 7.0
  • lite OK

書式

arctan2(x,y)
x
横成分の距離
y
縦成分の距離

戻り値

arctan(y/x)の値を-π〜+πで返す。

機能

xとyを指定することによって、全方位をカバーするアークタンジェントを返します。

Example

r = round(radtodeg(arctan2(-1,-1)));     /* r is -135 */

マウスポインタに向かって減衰しながら移動するサンプル

Objectのscriptで以下のように記述する

dx = mouse_x - x
dy = mouse_y - y

// calc direction
direction = radtodeg(arctan2(-dy, dx))

// calc speed
length = sqrt(sqr(dx) + sqr(dy))
speed = 5 * length / 100

ただし目的への角度を取得するだけなら、point_direction()で代用できる。

// calc direction
direction = point_direction(x, y, mouse_x, mouse_y);

// calc speed
length = point_distance(x, y, mouse_x, mouse_y);
speed = 5 * length / 100

参照

Wiki内検索

#search(): You already view a search box

MENU

ドキュメント

GMLリファレンス

2ch

その他



最新の30件

2024-03-07 2023-08-09 2023-05-21 2023-05-20 2023-05-04 2022-10-13 2022-07-21 2022-07-02 2022-04-06 2021-11-30 2021-11-26 2021-10-03 2021-09-23 2021-08-15 2021-06-02 2021-01-23 2021-01-21 2021-01-19 2021-01-18 2021-01-16 2021-01-15

人気の10件

今日の10件



これまでの訪問者: 3791
今日の訪問者: 2
昨日の訪問者: 1
閲覧者: 3