phaser/src/math/Rotate.js

30 lines
855 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
2017-10-06 03:52:41 +00:00
/**
2018-04-24 06:22:05 +00:00
* Rotate a given point by a given angle around the origin (0, 0), in an anti-clockwise direction.
2017-10-06 03:52:41 +00:00
*
* @function Phaser.Math.Rotate
* @since 3.0.0
*
2018-04-24 06:22:05 +00:00
* @param {(Phaser.Geom.Point|object)} point - The point to be rotated.
* @param {number} angle - The angle to be rotated by in an anticlockwise direction.
2017-10-06 03:52:41 +00:00
*
2018-04-24 06:22:05 +00:00
* @return {Phaser.Geom.Point} The given point, rotated by the given angle in an anticlockwise direction.
2017-10-06 03:52:41 +00:00
*/
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;