From 5e2a1e5df90686a39f617e79af0e138ff476079e Mon Sep 17 00:00:00 2001 From: liabru Date: Thu, 24 Apr 2014 12:19:52 +0100 Subject: [PATCH] added Vector.angle --- src/geometry/Vector.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/geometry/Vector.js b/src/geometry/Vector.js index 628709e..924fbae 100644 --- a/src/geometry/Vector.js +++ b/src/geometry/Vector.js @@ -163,4 +163,15 @@ var Vector = {}; return { x: -vector.x, y: -vector.y }; }; + /** + * Returns the angle in radians between the two vectors relative to the x-axis + * @method angle + * @param {vector} vectorA + * @param {vector} vectorB + * @return {number} The angle in radians + */ + Vector.angle = function(vectorA, vectorB) { + return Math.atan2(vectorB.y - vectorA.y, vectorB.x - vectorA.x); + }; + })(); \ No newline at end of file