phaser/v3/merge/vec2/Angle.js

14 lines
342 B
JavaScript
Raw Normal View History

2017-02-04 04:41:17 +00:00
import Clamp from 'math/Clamp.js';
// Get the angle in radians between the two given vectors
export default function (a, b) {
const dot = a[0] * b[0] + a[1] * b[1];
const len = Math.sqrt(a[0] * a[0] + a[1] * a[1]);
const lenV = Math.sqrt(b[0] * b[0] + b[1] * b[1]);
return Math.acos(Clamp(dot / (len * lenV), -1, 1));
}