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
|
|
|
/**
|
2020-04-24 20:10:06 +00:00
|
|
|
* Rotate a `point` around `x` and `y` to the given `angle`, at the same distance.
|
|
|
|
*
|
|
|
|
* In polar notation, this maps a point from (r, t) to (r, angle), vs. the origin (x, y).
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.RotateAround
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @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.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @return {Phaser.Geom.Point} The given point, rotated by the given angle around the given coordinates.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2017-01-03 22:47:26 +00:00
|
|
|
var RotateAround = function (point, x, y, angle)
|
2016-12-07 17:16:59 +00:00
|
|
|
{
|
|
|
|
var c = Math.cos(angle);
|
|
|
|
var s = Math.sin(angle);
|
|
|
|
|
2017-01-03 22:47:26 +00:00
|
|
|
var tx = point.x - x;
|
|
|
|
var ty = point.y - y;
|
2016-12-07 17:16:59 +00:00
|
|
|
|
2017-01-03 22:47:26 +00:00
|
|
|
point.x = tx * c - ty * s + x;
|
|
|
|
point.y = tx * s + ty * c + y;
|
2016-12-07 17:16:59 +00:00
|
|
|
|
2017-01-03 22:47:26 +00:00
|
|
|
return point;
|
2016-12-07 17:16:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RotateAround;
|