math

Properties

enum Axis number

Axis direction

Axis.X: 0
Axis.Y: 1
Axis.Z: 2
enum ClipTest number

Plane or frustum clip test result type.

ClipTest.Inside: 0   // The object is completely inside the frustum or in front of the plane.
ClipTest.Outside: 1  // The object is completely outside the frustum or behind the plane.
ClipTest.Overlap: 2  // The object overlaps the plane or frustum.
static, constant DegreeToRadian number

Conversion value for degrees to radians.

static, constant Epsilon number

General value to consider as an epsilon for float comparisons.

static, constant MaxValue number

General value to consider as a maximum float value.

static, constant PI number

3.1415...

static, constant PI2 number

PI multiplied by 2

static, constant PI_2 number

PI divided by 2

static, constant RadianToDegree number

Conversion value for radians to degrees.

enum RotationOrder number

Order in which to apply euler rotations for a transformation.

RotationOrder.Default: RotationOrder.ZYX
RotationOrder.ZYX: 0
RotationOrder.XYZ: 1,
RotationOrder.XZY: 2,
RotationOrder.YZX: 3,
RotationOrder.YXZ: 4,
RotationOrder.ZXY: 5,

Methods

static clamp(x, min, max) → number

Clamp the value x to the range [min, max].

Parameters
x number
min number
max number
Returns
number

static copysign(a, b) → number

Apply the sign of b to a.

Parameters
a number
b number
Returns
number

static equals(a, b, epsilon) → bool

Compare two floating-point numbers, testing if the two numbers closer than the given epsilon.

Parameters
a number
b number
epsilon number
Returns
bool

static isPowerOfTwo(v) → bool

Is the given number a power of 2?

Parameters
v number
Returns
bool

static ldexp(mantissa, exponent)

Implementation of the C ldexp function, which combines a mantessa and exponent into a floating-point number. http://croquetweak.blogspot.com/2014/08/deconstructing-floats-frexp-and-ldexp.html

Parameters
mantissa number
exponent number

static length3(x, y, z) → number

The length of a 3-dimensional vector, given by its components.

Parameters
x number
y number
z number
Returns
number

static lerp(x, min, max) → number

Linear interpolate between [min, max] using x. If x is outside of the range [min, max], the interpolated value will be a linear extrapolation.

Parameters
x number

The interpolation amount, in the range [0, 1].

min number

The start of the range to interpolate.

max number

The end of the range to interpolate.

Returns
number

The interpolated value.

static nearestPowerOfTwo(v) → number

Return the closest power-of-2 of the given number.

Parameters
v number
Returns
number

static pingpong(x, min, max) → number

If x is outside of the range [min, max], the interval will be ping-ponged.

Parameters
x number
min number
max number
Returns
number

static radiansToDegrees(a) → number

Convert radians to degrees.

Parameters
a number
Returns
number

static repeat(x, min, max) → number

If x is outside of the range [min, max], the interval will be repeated.

Parameters
x number
min number
max number
Returns
number

static solveCubic(a, b, c, d, roots) → number

Solves the cubic equation: a + bx + cx^2 + d*x^3 = 0

Parameters
a number
b number
c number
d number
roots Array.<number>

The resulting roots

Returns
number

The number of roots found

static solveQuadratic(a, b, c, roots) → number

Solves the quadratic equation: a + bx + cx^2 = 0

Parameters
a number
b number
c number
roots Array.<number>

The resulting roots

Returns
number

The number of roots found

static solveQuartic(a, b, c, d, e, roots) → number

Solve the quartic equation: a + bx + cx^2 + dx^3 + ex^4 = 0

Parameters
a number
b number
c number
d number
e number
roots Array.<number>

The resulting roots

Returns
number

The number of roots found

static toFloat16(value) → number

Convert a float32 number to a float16.

ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript This method is faster than the OpenEXR implementation, with the additional benefit of rounding, inspired by James Tursa?s half-precision code

Parameters
value number

The number to convert

Returns
number

The float16 value

inner abs(x)

Returns the absolute value of x.

Parameters
x number

inner acos(x) → number

Returns the arccosine of x.

Parameters
x number
Returns
number

inner asin(x) → number

Returns the arcsine of x.

Parameters
x number
Returns
number

inner ceil(x) → number

Returns the smallest integer greater than or equal to x.

Parameters
x number
Returns
number

inner cos(x) → number

Returns the cosine of x.

Parameters
x number
Returns
number

inner floor(x) → number

Returns the largest integer less than or equal to x.

Parameters
x number
Returns
number

inner log(x) → number

Returns the natural logarithm of x.

Parameters
x number
Returns
number

inner sign(x) → number

Returns the sign of x, indicating whether x is positive, negative, or zero.

Parameters
x number
Returns
number

inner sin(x) → number

Returns the sine of x.

Parameters
x number
Returns
number

inner sqrt(x) → number

Returns the square root of x.

Parameters
x number
Returns
number

inner sqrt(x) → number

Returns the arctangent of x.

Parameters
x number
Returns
number

inner tan(x) → number

Returns the tangent of x.

Parameters
x number
Returns
number