Class MathEx

Set of math helper functions.

Methods

randomBetween(a, b) static method

Generates a random number in given range.

Parameters
a : number — A lower value.
b : number — A greater value.
Returns
number
clamp(value, min, max) static method

Clamps given value to min max range.

Parameters
value : number — A value to clamp.
min : number — A lower threshold.
max : number — A greater threshold.
Returns
number
distance(x1, y1, x2, y2) static method

Calculates distance between two points.

Parameters
x1 : number — First point x-coordinate.
y1 : number — First point y-coordinate.
x2 : number — Second point x-coordinate.
y2 : number — Second point y-coordinate.
Returns
number
distanceSqr(x1, y1, x2, y2) static method

Calculates squared distance between two points.

Parameters
x1 : number — First point x-coordinate.
y1 : number — First point y-coordinate.
x2 : number — Second point x-coordinate.
y2 : number — Second point y-coordinate.
Returns
number
angleBetween(x1, y1, x2, y2) static method

Calculates angle in radians between two points.

Parameters
x1 : number — First point x-coordinate.
y1 : number — First point y-coordinate.
x2 : number — Second point x-coordinate.
y2 : number — Second point y-coordinate.
Returns
number
mapRange(value, fromA, fromB, toA, toB) static method

Maps one range onto another.

Parameters
value : number — A value to map.
fromA : number — Lower value from first range.
fromB : number — Greater value from first range.
toA : number — Lower value from second range.
toB : number — Greater value from second range.
Returns
number
lerp(a, b, t) static method

Linearly interpolates a number.

Parameters
a : number — First value.
b : number — Second value.
t : number — A value between 0 and 1.
Returns
number
equals(a, b, epsilon) static method

Compares two numbers using given epsilon value.

Parameters
a : number — First value.
b : number — Second value.
epsilon : number — Comparison threshold.
Returns
boolean

Properties

PI_Q static property
Pi divided by 4.
PI2 static property
PI multiplied by 2.
RAD2DEG static property
Radians to degrees constant.
DEG2RAD static property
Degrees to radians constant.