LoginSignup
3
3

More than 3 years have passed since last update.

2つのベクトルの内積から角度を得る

Last updated at Posted at 2020-01-27
var a = {x:0,y:100};
var b = {x:10,y:20};

//内積
var dot = a.x * b.x + a.y * b.y;

//絶対値
var absA = Math.sqrt(a.x*a.x + a.y*a.y);
var absB = Math.sqrt(b.x*b.x + b.y*b.y);

//dot = |a||b|cosθという公式より
var cosTheta = dot / (absA*absB);

//すでにベクトルがノーマライズされてたら dotのみでいける

//cosθの逆関数
var theta = Math.acos(cosTheta);
3
3
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
3
3