Packagealternativa.utils
Classpublic final class MathUtils

Math utilities and constants. All vector operations are made on a plane.



Public Methods
 MethodDefined by
  
deltaAngle(a:Number, b:Number):Number
[static]Get minimal angles difference.
MathUtils
  
equals(a:Number, b:Number, threshold:Number = 0):Boolean
[static]Compare numbers with given treshold.
MathUtils
  
limitAngle(angle:Number):Number
[static]Convert angle value to -180.
MathUtils
  
random(a:Number, b:Number):Number
[static]Get random number.
MathUtils
  
randomAngle():Number
[static]Get random angle value in 0.
MathUtils
  
segmentDistance(first:Point, second:Point, point:Point):Number
[static]A distance from point to a line, set by two points.
MathUtils
  
toDegree(angle:Number):Number
[static]Convert radians to degrees.
MathUtils
  
toRadian(angle:Number):Number
[static]Convert degrees to radians.
MathUtils
  
triangleHasPoint(a:Point, b:Point, c:Point, point:Point):Boolean
[static]Check if point is in triangle.
MathUtils
  
vectorAngle(a:Point, b:Point):Number
[static]Calculate angle between vectors.
MathUtils
  
vectorAngleFast(a:Point, b:Point):Number
[static]Calculate angle between unit vectors.
MathUtils
  
vectorCross(a:Point, b:Point):Number
[static]Calculate cross product of two vectors
MathUtils
  
vectorDot(a:Point, b:Point):Number
[static]Calculate dot product.
MathUtils
Public Constants
 ConstantDefined by
  DEG1 : Number
[static] 1 degree angle in radians.
MathUtils
  DEG10 : Number
[static] 10 degree angle in radians.
MathUtils
  DEG180 : Number = 3.141592653589793
[static] 180 degree angle in radians.
MathUtils
  DEG30 : Number
[static] 30 degree angle in radians.
MathUtils
  DEG360 : Number
[static] 360 degree angle in radians.
MathUtils
  DEG45 : Number
[static] 45 degree angle in radians.
MathUtils
  DEG5 : Number
[static] 5 degree angle in radians.
MathUtils
  DEG60 : Number
[static] 60 degree angle in radians.
MathUtils
  DEG90 : Number
[static] 90 degree angle in radians.
MathUtils
Method detail
deltaAngle()method
public static function deltaAngle(a:Number, b:Number):Number

Get minimal angles difference. Angles are limited by -180...180 range.

Parameters
a:Numberfirst angle
 
b:Numbersecond angle

Returns
Numberminimum difference between angles
equals()method 
public static function equals(a:Number, b:Number, threshold:Number = 0):Boolean

Compare numbers with given treshold.

Parameters
a:Numberfirst number
 
b:Numbersecond number
 
threshold:Number (default = 0)threshold

Returns
Booleantrue if absolute difference of the values doesn't exceed given threshold, otherwise false
limitAngle()method 
public static function limitAngle(angle:Number):Number

Convert angle value to -180...180 limits

Parameters
angle:Numberangle

Returns
Numberan equivalent angle from [-180,180] degree interval for the cpecified value
random()method 
public static function random(a:Number, b:Number):Number

Get random number.

Parameters
a:Numberinterval beginning
 
b:Numberinterval ending

Returns
Numbera random value from [0, 1] interval if parameter a isn't specified, a random value from [0, a] interval if parameter a is specified and parameter b isn't specified, a random value from [a, b] interval if both parameters are specified
randomAngle()method 
public static function randomAngle():Number

Get random angle value in 0...360 range.

Returns
Numbera random angle value from 0..360 degree range
segmentDistance()method 
public static function segmentDistance(first:Point, second:Point, point:Point):Number

A distance from point to a line, set by two points.

Parameters
first:Pointfirst line point
 
second:Pointsecond line point
 
point:Pointpoint

Returns
Numbera distance to a line
toDegree()method 
public static function toDegree(angle:Number):Number

Convert radians to degrees.

Parameters
angle:Numberangle in radians

Returns
Numberangle value in degrees
toRadian()method 
public static function toRadian(angle:Number):Number

Convert degrees to radians.

Parameters
angle:Numberangle in degrees

Returns
Numberangle value in radians
triangleHasPoint()method 
public static function triangleHasPoint(a:Point, b:Point, c:Point, point:Point):Boolean

Check if point is in triangle.

Parameters
a:Pointfirst triangle point
 
b:Pointsecond triangle point
 
c:Pointthird triangle point
 
point:Pointpoint that is being checked

Returns
Booleantrue if the point belongs to the triangle, false otherwise
vectorAngle()method 
public static function vectorAngle(a:Point, b:Point):Number

Calculate angle between vectors.

Parameters
a:Pointfirst vector
 
b:Pointsecond vector

Returns
Numberangle between vectors in radians
vectorAngleFast()method 
public static function vectorAngleFast(a:Point, b:Point):Number

Calculate angle between unit vectors.

Parameters
a:Pointfirst unit vector
 
b:Pointsecond unit vector

Returns
Numberangle between vectors in radians
vectorCross()method 
public static function vectorCross(a:Point, b:Point):Number

Calculate cross product of two vectors

Parameters
a:Pointfirst vector
 
b:Pointsecond vector

Returns
Numbercross product a × b
vectorDot()method 
public static function vectorDot(a:Point, b:Point):Number

Calculate dot product.

Parameters
a:Pointfirst vector
 
b:Pointsecond vector

Returns
Numberdot product of the specified vectors
Constant detail
DEG1constant
public static const DEG1:Number

1 degree angle in radians.

DEG10constant 
public static const DEG10:Number

10 degree angle in radians.

DEG180constant 
public static const DEG180:Number = 3.141592653589793

180 degree angle in radians.

DEG30constant 
public static const DEG30:Number

30 degree angle in radians.

DEG360constant 
public static const DEG360:Number

360 degree angle in radians.

DEG45constant 
public static const DEG45:Number

45 degree angle in radians.

DEG5constant 
public static const DEG5:Number

5 degree angle in radians.

DEG60constant 
public static const DEG60:Number

60 degree angle in radians.

DEG90constant 
public static const DEG90:Number

90 degree angle in radians.