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-12-03 15:16:23 +00:00
|
|
|
* Rotate a `point` around `x` and `y` by the given `angle` and `distance`.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2020-04-24 20:10:06 +00:00
|
|
|
* In polar notation, this maps a point from (r, t) to (distance, t + angle), vs. the origin (x, y).
|
|
|
|
*
|
2017-10-06 03:52:41 +00:00
|
|
|
* @function Phaser.Math.RotateAroundDistance
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-04-24 20:30:07 +00:00
|
|
|
* @generic {Phaser.Math.Vector2Like} T - [point,$return]
|
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @param {(Phaser.Geom.Point|object)} point - The point to be rotated.
|
2017-10-06 03:52:41 +00:00
|
|
|
* @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.
|
2018-12-03 15:16:23 +00:00
|
|
|
* @param {number} distance - The distance from (x, y) to place the point at.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2020-04-24 20:30:07 +00:00
|
|
|
* @return {Phaser.Math.Vector2Like} The given point.
|
2017-10-06 03:52:41 +00:00
|
|
|
*/
|
2017-01-03 22:47:26 +00:00
|
|
|
var RotateAroundDistance = function (point, x, y, angle, distance)
|
|
|
|
{
|
|
|
|
var t = angle + Math.atan2(point.y - y, point.x - x);
|
|
|
|
|
|
|
|
point.x = x + (distance * Math.cos(t));
|
|
|
|
point.y = y + (distance * Math.sin(t));
|
|
|
|
|
|
|
|
return point;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RotateAroundDistance;
|