LoginSignup
13
12

More than 5 years have passed since last update.

ベクトルの角度を求める

Posted at

三角関数とかもう覚えてないわーってことでメモ。
原点から x, y の座標へのベクトルが x 軸から何度あるのか求めるのを javascript で。
(chrome の console で気軽に求められるので)

calculate_cosine = function (x, y) { return x / Math.sqrt(x*x + y*y); };
calculate_radian = function (cos) { return Math.acos(cos) / (Math.PI / 180); };

座標 x = 50, y = 20 のときはこうなる。

> calculate_radian( calculate_cosine(50, 20) );
21.80140948635181
13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12