//constructor
function Vector (X,Y) {
 this.Set(X,Y);
}

Vector.prototype.copy = function(target) {
 for (var _field in target) this[_field] = target[_field];
}

Vector.prototype.set = function(X, Y) {
 this._length = Math.sqrt(X*X + Y*Y);
 this._cos = Math.cos(this._angle = Math.atan2(this._y = Y, this._x = X));
 this._sin = Math.sin(this._angle);
 this._rotation = this._angle * 180/Math.PI;
}

Vector.prototype.Add = function(target) {
 this.set(this._x + target._x, this._y + target._y);
}

Vector.prototype.mul = function(value) {
 this.setLength(this._length * value);
}

Vector.prototype.setLength = function(value) {
 this._x = value * this._cos;
 this._y = value * this._sin;
 this._length = Math.abs(value);
 if (Value < 0) {
  this._cos = -this._cos;
  this._sin = -this._sin;
  this._angle += Math.PI;
  this._rotation += 180;
 }
}

// set specified angle(radians)
Vector.prototype.setAngle = function(value) {
 this._rotation = value * 180/Math.PI;
 this._x = this._length * (this._cos = Math.cos(this._angle = value));
 this._y = this._length * (this._sin = Math.sin(value));
}

// set specified angle(degrees)
Vector.prototype.setRotation = function(value) {
 this.setAngle(value * Math.PI/180);
}

// add a specified angle(degrees) to a vector
Vector.prototype.rotate = function(Value) {
 this.setRotation(this._rotation + Value);
}

// analysis along target
Vector.prototype.splitAlong = function(target) {
 return (target._length == 0? 0: (this._x * target._x + this._y * target._y) / (target._length * target._length));
}

Vector.prototype.asideOffset = function(X,Y) {
 return Math.sqrt(X*X + Y*Y - (Addi2 =( X*this._x + Y*this._y)/this._length) * Addi2);
}