Added Vector2.angle method

This commit is contained in:
Richard Davey 2017-09-20 23:10:03 +01:00
parent 9d3c80ab0c
commit aab4896582

View file

@ -50,6 +50,20 @@ var Vector2 = new Class({
return this;
},
angle: function () {
// computes the angle in radians with respect to the positive x-axis
var angle = Math.atan2(this.y, this.x);
if (angle < 0)
{
angle += 2 * Math.PI;
}
return angle;
},
add: function (src)
{
this.x += src.x;