phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
32 lines (27 loc) • 949 B
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2026 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Rotate a given point by a given angle around the origin (0, 0), in an anti-clockwise direction.
*
* @function Phaser.Math.Rotate
* @since 3.0.0
*
* @generic {Phaser.Types.Math.Vector2Like} T - [point,$return]
*
* @param {Phaser.Types.Math.Vector2Like} point - The point to be rotated.
* @param {number} angle - The angle to rotate by, in radians, in an anti-clockwise direction.
*
* @return {Phaser.Types.Math.Vector2Like} The given point, rotated by the given angle in an anti-clockwise direction.
*/
var Rotate = function (point, angle)
{
var x = point.x;
var y = point.y;
point.x = (x * Math.cos(angle)) - (y * Math.sin(angle));
point.y = (x * Math.sin(angle)) + (y * Math.cos(angle));
return point;
};
module.exports = Rotate;