Angle utility functions.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@416 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -34,6 +34,41 @@ public class MathUtil
|
|||||||
return Math.min(Math.max(n, min), max);
|
return Math.min(Math.max(n, min), max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts degrees to radians.
|
||||||
|
*/
|
||||||
|
public static function toRadians (degrees :Number) :Number
|
||||||
|
{
|
||||||
|
return degrees * Math.PI / 180;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes an angle in radians to occupy the [0, 2pi) range.
|
||||||
|
*/
|
||||||
|
public static function normalizeRadians (radians :Number) :Number
|
||||||
|
{
|
||||||
|
var twopi :Number = Math.PI * 2;
|
||||||
|
var norm :Number = radians % twopi;
|
||||||
|
return (norm >= 0) ? norm : (norm + twopi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts radians to degrees.
|
||||||
|
*/
|
||||||
|
public static function toDegrees (radians :Number) :Number
|
||||||
|
{
|
||||||
|
return radians * 180 / Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes an angle in degrees to occupy the [0, 360) range.
|
||||||
|
*/
|
||||||
|
public static function normalizeDegrees (degrees :Number) :Number
|
||||||
|
{
|
||||||
|
var norm :Number = degrees % 360;
|
||||||
|
return (norm >= 0) ? norm : (norm + 360);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns distance from point (x1, y1) to (x2, y2) in 2D.
|
* Returns distance from point (x1, y1) to (x2, y2) in 2D.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user