The MathUtil class includes a collection of trigonometry and coordinate system utilities.
ActionScript 2.0; Flash Player 6
Property summary
Property | Description |
---|---|
DEG2RAD:Number |
Change degrees to radians
|
RAD2DEG:Number |
Change radians to degrees
|
PHI:Number |
The golden mean (phi)
|
LAMBDA:Number |
Euler-Mascheroni constant (lambda or C)
|
Method summary
Method | Description |
---|---|
distance(x1:Number, y1:Number, x2:Number, y2:Number) : Number |
Finds the distance between two points. |
distancePts(p1:Object, p2:Object) : Number |
Finds the distance between two points. |
angleOfLine(x1:Number, y1:Number, x2:Number, y2:Number) : Number |
Finds the angle of the line formed between two points. |
angleOfLinePts(p1:Object, p2:Object) : Number |
Finds the angle of the line formed between two points. |
fixAngle(angle:Number) : Number |
Takes an angle in degrees and returns the equivalent standardized angle between 0 and 360 degrees. |
degreesToRadians(angle:Number) : Number |
Changes degrees to radians. |
radiansToDegrees(angle:Number) : Number |
Changes radians to degrees. |
randRangeFloat(low:Number, high:Number) : Number |
Returns a random floating-point number between two numbers. |
randRangeInt(low:Number, high:Number) : Number |
Returns a random integer between two numbers. |
var x1:Number = 10;
var y1:Number = 10;
var x2:Number = 20;
var y2:Number = 20;
trace (MathUtil.distance(x1, y1, x2, y2));
x1:Number
- The x value of the first point.
y1:Number
- The y value of the first point.
x2:Number
- The x value of the second point.
y2:Number
- The y value of the second point.
Returns the distance between the two points.
Finds the distance between two points.
var p1:Object = {x:10, y:10};
var p2:Object = {x:20, y:20};
trace (MathUtil.distancePts(p1, p2));
p1:Object
- The first point, with x and y properties.
p2:Object
- The second point, with x and y properties.
Returns the distance between the two points.
Finds the distance between two points.
var x1:Number = 10;
var y1:Number = 10;
var x2:Number = 20;
var y2:Number = 20;
trace (MathUtil.angleOfLine(x1, y1, x2, y2));
x1:Number
- The x value of the first point.
y1:Number
- The y value of the first point.
x2:Number
- The x value of the second point.
y2:Number
- The y value of the second point.
Returns the angle of the line formed between the two points.
Finds the angle of the line formed between two points.
var p1:Object = {x:10, y:10};
var p2:Object = {x:20, y:20};
trace (MathUtil.angleOfLinePts(p1, p2));
p1:Object
- The first point, with x and y properties.
p2:Object
- The second point, with x and y properties.
Returns the angle of the line formed between the two points.
Finds the angle of the line formed between two points.
trace (MathUtil.fixAngle(740));
trace (MathUtil.fixAngle(-340));
trace (MathUtil.fixAngle(20));
angle:Number
- The angle below 0 or above 360.
Returns the equivalent standardized angle between 0 and 360 degrees.
Takes an angle in degrees and returns the equivalent standardized angle between 0 and 360 degrees.
var angleDegrees:Number = 180;
var angleRadians:Number = MathUtil.degreesToRadians(angleDegrees);
trace (angleRadians);
angle:Number
- The angle in degrees.
Returns the angle in radians.
Changes degrees to radians.
trace (MathUtil.radiansToDegrees(Math.PI));
angle:Number
- The angle in radians.
Returns the angle in degrees.
Changes radians to degrees.
trace (MathUtil.randRangeFloat(-.1, .1));
low:Number
- The low number of the random range.
high:Number
- The high number of the random range.
Returns a random floating-point number between two numbers.
Returns a random floating-point number between two numbers.
trace (MathUtil.randRangeInt(-10, 10));
low:Number
- The low number of the random range.
high:Number
- The high number of the random range.
Returns a random integer between two numbers.
Returns a random integer between two numbers.
trace (Constant.DEG2RAD * 180);
Change degrees to radians
Math.PI/180
trace (Constant.RAD2DEG * Math.PI);
Change radians to degrees
180/Math.PI
trace (Constant.PHI);
The golden mean (phi)
(1+Math.sqrt(5))/2
trace (Constant.LAMBDA);
Euler-Mascheroni constant (lambda or C)
( n )
lim ( sigma 1/k - ln(n) )
n->oo ( k=1 )