Module: math
Math additional functionallity
Methods
(static) angle(a, b) → {float}
Calculates angle between 2 vectors
Parameters:
Name | Type | Description |
---|---|---|
a | module:math~Vector | |
b | module:math~Vector |
Returns:
Angle between vectors a and b
Type
float
(static) clamp(v, min, max) → {float}
Clamp value in range
Parameters:
Name | Type | Description |
---|---|---|
v | float | Value to clamp |
min | float|module:math~Range | Min boundary or range |
max | float | Max 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:
Name | Type | Description |
---|---|---|
pX | float | |
pY | float | |
aX | float | |
aY | float | |
bX | float | |
bY | float |
Returns:
cross product
Type
float
(static) degToRad(value) → {float}
Convert degrees to radians
Parameters:
Name | Type | Description |
---|---|---|
value | float | Degrees |
Returns:
Radians
Type
float
(static) mapTo(v, src, dest)
Maps value from src to dest range
Parameters:
Name | Type | Description |
---|---|---|
v | float | Value |
src | module:math~Range | Value range |
dest | module:math~Range | Target range |
Returns:
mapped value
(static) perpendicularDistance(pX, pY, aX, aY, bX, bY) → {float}
Perpendicular distance using cross product
Parameters:
Name | Type | Description |
---|---|---|
pX | float | |
pY | float | |
aX | float | |
aY | float | |
bX | float | |
bY | float |
See:
Returns:
Perpendicular distance
Type
float
(static) radToDeg(value) → {float}
Convert radians to degrees
Parameters:
Name | Type | Description |
---|---|---|
value | float | Radians |
Returns:
Degrees
Type
float
(static) randomInt(min, max) → {int}
Based on Math random() implementation, scaled to int range.
Parameters:
Name | Type | Description |
---|---|---|
min | int | |
max | int |
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:
Name | Type | Description |
---|---|---|
a | Common.Point | |
b | Common.Point |
Returns:
Vector between points a and b
Type
Type Definitions
Range
The area of variation between upper and lower limits
Properties:
Name | Type | Description |
---|---|---|
min | float | Min value limit |
max | float | Max value limit |
Vector
Vector representation
Properties:
Name | Type | Description |
---|---|---|
x | float | Vector direction x |
y | float | Vector direction y |
length | float | Vector length |