mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Added RotateAroundDistance and tidied up other Rotate functions.
This commit is contained in:
parent
1712560c6e
commit
196f57c869
4 changed files with 28 additions and 12 deletions
|
@ -1,13 +1,14 @@
|
|||
// p = Point or any object with public x/y properties
|
||||
var Rotate = function (p, angle)
|
||||
|
||||
var Rotate = function (point, angle)
|
||||
{
|
||||
var x = p.x;
|
||||
var y = p.y;
|
||||
var x = point.x;
|
||||
var y = point.y;
|
||||
|
||||
p.x = x * Math.cos(angle) - y * Math.sin(angle);
|
||||
p.y = x * Math.sin(angle) + y * Math.cos(angle);
|
||||
point.x = (x * Math.cos(angle)) - (y * Math.sin(angle));
|
||||
point.y = (x * Math.sin(angle)) + (y * Math.cos(angle));
|
||||
|
||||
return p;
|
||||
return point;
|
||||
};
|
||||
|
||||
module.exports = Rotate;
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
// p = Point or any object with public x/y properties
|
||||
var RotateAround = function (p, cx, cy, angle)
|
||||
|
||||
var RotateAround = function (point, x, y, angle)
|
||||
{
|
||||
var c = Math.cos(angle);
|
||||
var s = Math.sin(angle);
|
||||
|
||||
var x = p.x - cx;
|
||||
var y = p.y - cy;
|
||||
var tx = point.x - x;
|
||||
var ty = point.y - y;
|
||||
|
||||
p.x = x * c - y * s + cx;
|
||||
p.y = x * s + y * c + cy;
|
||||
point.x = tx * c - ty * s + x;
|
||||
point.y = tx * s + ty * c + y;
|
||||
|
||||
return p;
|
||||
return point;
|
||||
};
|
||||
|
||||
module.exports = RotateAround;
|
||||
|
|
13
v3/src/math/RotateAroundDistance.js
Normal file
13
v3/src/math/RotateAroundDistance.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
// p = Point or any object with public x/y properties
|
||||
|
||||
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;
|
|
@ -35,6 +35,7 @@ module.exports = {
|
|||
RadToDeg: require('./RadToDeg'),
|
||||
Rotate: require('./Rotate'),
|
||||
RotateAround: require('./RotateAround'),
|
||||
RotateAroundDistance: require('./RotateAroundDistance'),
|
||||
RoundAwayFromZero: require('./RoundAwayFromZero'),
|
||||
RoundTo: require('./RoundTo'),
|
||||
SinCosTableGenerator: require('./SinCosTableGenerator'),
|
||||
|
|
Loading…
Add table
Reference in a new issue