xxxxxxxxxx
function rotate(angle: number) {
this.angle += angle
this.x = Math.cos(this.angle) * this.length
this.y = Math.sin(this.angle) * this.length
}
xxxxxxxxxx
/**
* @function rotateVector
* @param {Vector} vector
* @param {number} angle
* @returns {Vector}
* @description Rotates a vector by an angle
*/
export function rotateVector(vector: Vector, angle: number): Vector {
let x = vector.x * Math.cos(angle) - vector.y * Math.sin(angle)
let y = vector.x * Math.sin(angle) + vector.y * Math.cos(angle)
return new Vector(x, y)
}
xxxxxxxxxx
var rotateVector = function(vec, ang)
{
ang = -ang * (Math.PI/180);
var cos = Math.cos(ang);
var sin = Math.sin(ang);
return new Array(Math.round(10000*(vec[0] * cos - vec[1] * sin))/10000, Math.round(10000*(vec[0] * sin + vec[1] * cos))/10000);
};