Skip to main content

Module: math

Math additional functionallity

Methods

(static) angle(a, b) → {float}

Calculates angle between 2 vectors

Parameters:
NameTypeDescription
amodule:math~Vector
bmodule:math~Vector
Returns:

Angle between vectors a and b

Type

float

(static) clamp(v, min, max) → {float}

Clamp value in range

Parameters:
NameTypeDescription
vfloatValue to clamp
minfloat|module:math~RangeMin boundary or range
maxfloatMax boundary, when min is Range is ignored
Returns:

Clamped value

Type

float

(static) cross(pX, pY, aX, aY, bX, bY) → {float}

2D cross product of OA and OB vectors, i.e. z-component of their 3D cross product.Returns a positive value, if OAB makes a counter-clockwise turn,negative for clockwise turn, and zero if the points are collinear.

Parameters:
NameTypeDescription
pXfloat
pYfloat
aXfloat
aYfloat
bXfloat
bYfloat
Returns:

cross product

Type

float

(static) degToRad(value) → {float}

Convert degrees to radians

Parameters:
NameTypeDescription
valuefloatDegrees
Returns:

Radians

Type

float

(static) mapTo(v, src, dest)

Maps value from src to dest range

Parameters:
NameTypeDescription
vfloatValue
srcmodule:math~RangeValue range
destmodule:math~RangeTarget range
Returns:

mapped value

(static) perpendicularDistance(pX, pY, aX, aY, bX, bY) → {float}

Perpendicular distance using cross product

Parameters:
NameTypeDescription
pXfloat
pYfloat
aXfloat
aYfloat
bXfloat
bYfloat

See:

Returns:

Perpendicular distance

Type

float

(static) radToDeg(value) → {float}

Convert radians to degrees

Parameters:
NameTypeDescription
valuefloatRadians
Returns:

Degrees

Type

float

(static) randomInt(min, max) → {int}

Based on Math random() implementation, scaled to int range.

Parameters:
NameTypeDescription
minint
maxint
Returns:

Pseudo-random number between min (inclusive) and max (exclusive).

Type

int

(static) vector(a, b) → module:math~Vector

Calculates vector between 2 points

Parameters:
NameTypeDescription
aCommon.Point
bCommon.Point
Returns:

Vector between points a and b

Type

module:math~Vector

Type Definitions

Range

The area of variation between upper and lower limits

Properties:
NameTypeDescription
minfloatMin value limit
maxfloatMax value limit

Vector

Vector representation

Properties:
NameTypeDescription
xfloatVector direction x
yfloatVector direction y
lengthfloatVector length

Home