NumberUtils
| Kind of class: | class |
|---|---|
| Inherits from: | none |
| Author: | Arthur Clemens |
| Classpath: | org.asapframework.util.NumberUtils |
| File last modified: | Thursday, 12 October 2006, 23:23:05 |
Number utility functions.
Summary
Class methods
Class methods
angle
static function angle (
inDx:Number,
inDy:Number) : Number
Calculates the angle of a vector.
Parameters:
inDx:
the x component of the vector
inDy:
the y component of the vector
Returns:
The the angle of the passed vector in degrees.
normalizedValue
static function normalizedValue (
inValueToNormalize:Number,
inMinValue:Number,
inMaxValue:Number) : Number
Finds the normalized value (between 0 and 1) of the number inValueToNormalize, related to the normalized range, defined by lowest range value inMinValue and highest range value inMaxValue.
Normalizes a value, making it a value between 0 and 1
Normalizes a value, making it a value between 0 and 1
Parameters:
inValueToNormalize:
value to normalize
inMinValue :
min value
inMaxValue :
max value
Returns:
The normalized y value: a value between 0 and 1.
Example:
NumberUtils.normalizedValue(25, 0, 100); // 0.25 NumberUtils.normalizedValue(0, -1, 1); // 0.5
piOffset
static function piOffset (
inFindValue:Number,
inMinValue:Number,
inMaxValue:Number) : Number
Finds the x value of a point on a sine curve, of which only the y value is known. The closest x value is returned. This will range from -1 pi to 1 pi.
Parameters:
inFindValue:
y value of point to find on the sine curve
inMinValue :
min y value (bottom) of the sine curve
inMaxValue :
max y value (top) of the sine curve
Returns:
The offset value as multiplier of pi.
Implementation note:
Calls normalizedValue.
Example:
NumberUtils.piOffset(1, -1, 1); // 1.5707963267949 ( = 0.5 * Math.PI )
randomInRange
static function randomInRange (
inStartRange:Number,
inEndRange:Number) : Number
Creates a random number within a given range.
Parameters:
inStartRange:
lowest number of the range
inEndRange :
highest number of the range
Returns:
A new random number.
Example:
This example creates a random number between 10 and 20:
var scale:Number = NumberUtils.randomInRange(10, 20);
randomInRanges
static function randomInRanges (
inRanges:Array) : Number
Creates a random number within a list of ranges.
Pass a list of Arrays, each one separated by a comma.
Pass a list of Arrays, each one separated by a comma.
Returns:
A new random number.
Example:
This example creates a random number in between -45 and 40, or between 40 and 45:
var rotation:Number = NumberUtils.randomInRanges([-45, -40], [40, 45]);
truncate
static function truncate (
inNumber:Number,
inDigits:Number) : Number
Truncates floating point digits.
Parameters:
inNumber:
the number to truncate
inDigits:
the number of digits to keep after truncating
Returns:
A new number with truncated floating point digits.
Example:
var pi:Number = 3.14159265; pi = NumberUtils.truncate(pi, 2); // 3.14