MathUtils()

Class with various math helpers.

new MathUtils()

Author:

Methods

static area(a, b, c) → {Number}

Computes the signed area of a rectangle defined by three points. This method can also be used to calculate the area of a triangle.

Parameters:
Name Type Description
a Vector3

The first point in 3D space.

b Vector3

The second point in 3D space.

c Vector3

The third point in 3D space.

Returns:
Number -

The signed area.

static argmax(array) → {Array.<Number>}

Returns the indices of the maximum values of the given array.

Parameters:
Name Type Description
array Array.<Number>

The input array.

Returns:
Array.<Number> -

Array of indices into the array.

static choice(array, probabilities) → {Any}

Returns a random sample from a given array.

Parameters:
Name Type Default Description
array Array.<Any>

The array that is used to generate the random sample.

probabilities Array.<Number> null

The probabilities associated with each entry. If not given, the sample assumes a uniform distribution over all entries.

Returns:
Any -

The random sample value.

static clamp(value, min, max) → {Number}

Ensures the given scalar value is within a given min/max range.

Parameters:
Name Type Description
value Number

The value to clamp.

min Number

The min value.

max Number

The max value.

Returns:
Number -

The clamped value.

static generateUUID() → {String}

Computes a RFC4122 Version 4 complied Universally Unique Identifier (UUID).

Returns:
String -

The UUID.

static randFloat(min, max) → {Number}

Computes a random float value within a given min/max range.

Parameters:
Name Type Description
min Number

The min value.

max Number

The max value.

Returns:
Number -

The random float value.

static randInt(min, max) → {Number}

Computes a random integer value within a given min/max range.

Parameters:
Name Type Description
min Number

The min value.

max Number

The max value.

Returns:
Number -

The random integer value.