forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateAround.js
More file actions
34 lines (29 loc) · 991 Bytes
/
Copy pathRotateAround.js
File metadata and controls
34 lines (29 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Rotate a `point` around `x` and `y` by the given `angle`.
*
* @function Phaser.Math.RotateAround
* @since 3.0.0
*
* @param {(Phaser.Geom.Point|object)} point - The point to be rotated.
* @param {number} x - The horizontal coordinate to rotate around.
* @param {number} y - The vertical coordinate to rotate around.
* @param {number} angle - The angle of rotation in radians.
*
* @return {Phaser.Geom.Point} The given point, rotated by the given angle around the given coordinates.
*/
var RotateAround = function (point, x, y, angle)
{
var c = Math.cos(angle);
var s = Math.sin(angle);
var tx = point.x - x;
var ty = point.y - y;
point.x = tx * c - ty * s + x;
point.y = tx * s + ty * c + y;
return point;
};
module.exports = RotateAround;