The maths object provides useful methods for Developer and Engine internal use.
Properties:
Name | Type | Description |
---|---|---|
TO_RADIANS |
Number | Ratio for converting Degrees to Radians (i.e. Pi / 180) |
TO_DEGREES |
Number | Ratio for converting Radians to Degrees (i.e. 180 / Pi) |
TWOPI |
Number | (Pi * 2) |
Methods
(static) areaOfTriangle(len_or_Pnt1, len_or_Pnt2, len_or_Pnt3) → {Number}
Returns the surface area of a triangle from the lengths of it's sides (using Heron's formula)
Accepts either 3 lengths, or 3 points representing the corner co-ordinates can be used
CAUTION: do NOT mix parameter types
Parameters:
Name | Type | Description |
---|---|---|
len_or_Pnt1 |
Number | MC.Point | First side length or vertex coordinates |
len_or_Pnt2 |
Number | MC.Point | Second side length or vertex coordinates |
len_or_Pnt3 |
Number | MC.Point | Third side length or vertex coordinates |
Returns:
Area of the Triangle
- Type
- Number
(static) clamp(value, min, max) → {Number}
Clamps a number between a pair of values
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | Number to be clamped |
min |
Number | Minimum clamp value |
max |
Number | Maximum clamp value |
Returns:
The clamped value
- Type
- Number
(static) crossProd(x1_or_pnt1, y1_or_pnt2, x2opt, y2opt) → {Number}
Returns the Cross Product of two vectors (points) i.e. [(x1*y2)-(y1*x2)]
Points can be entered in either (Point1,Point2) OR (x1,y1,x2,y2) format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x1_or_pnt1 |
Number | MC.Point | First Point OR first point's x value | |
y1_or_pnt2 |
Number | MC.Point | Second Point OR first point's y value | |
x2 |
Number |
<optional> |
Second point's x value |
y2 |
Number |
<optional> |
Second point's y value |
Throws:
Console warning if neither 2 nor 4 arguments presented. 0 (zero) returned
Returns:
the Cross Product of the two vectors
- Type
- Number
(static) degToRad(angle) → {Number}
Degree to Radian convertion
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number | Angle in Degrees |
Returns:
Angle in Radians
- Type
- Number
(static) dotProd(x1_or_pnt1, y1_or_pnt2, x2opt, y2opt) → {Number}
Returns the Dot Product (aka Scalar Product) of two vectors (points) i.e. [(x1*x2)+(y1*y2)]
Points can be entered in either (Point1,Point2) OR (x1,y1,x2,y2) format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x1_or_pnt1 |
Number | MC.Point | First Point OR first point's x value | |
y1_or_pnt2 |
Number | MC.Point | Second Point OR first point's y value | |
x2 |
Number |
<optional> |
Second point's x value |
y2 |
Number |
<optional> |
Second point's y value |
Throws:
Console warning if neither 2 nor 4 arguments presented. 0 (zero) returned
Returns:
the Dot Product of the two vectors
- Type
- Number
(static) lerp(start, finish, ratio) → {Number|MC.Point}
Linear Interpolation between two values (either points or numbers)
Parameters:
Name | Type | Description |
---|---|---|
start |
Number | MC.Point | Starting (datum) point or number |
finish |
Number | MC.Point | Target point or number |
ratio |
Number | Proportion of travel required (N.B. decimals and -ve numbers are accepted) |
Throws:
Console warning when neither a pair of Points or numbers passed in. Start parameter is returned.
Returns:
- Type
- Number | MC.Point
(static) manhatten(x1_or_pnt1, y1_or_pnt2, x2opt, y2opt) → {Number}
Returns the manhatten distance between two points
Points can be entered in either (Point1,Point2) OR (x1,y1,x2,y2) format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x1_or_pnt1 |
Number | MC.Point | First Point OR first point's x value | |
y1_or_pnt2 |
Number | MC.Point | Second Point OR first point's y value | |
x2 |
Number |
<optional> |
Second point's x value |
y2 |
Number |
<optional> |
Second point's y value |
Throws:
Console warning if neither 2 nor 4 arguments presented. 0 (zero) returned
Returns:
the manhatten range between the points
- Type
- Number
(static) maxOf(arg) → {Number}
Returns the highest value in a list of arguments OR an array
Similar to Math.max() but works when passed an array of numbers
Parameters:
Name | Type | Description |
---|---|---|
arg |
Number | Array | Comma seperated list of numbers OR an Array of numbers |
Throws:
Console warning when nothing passed in. 0 (zero) returned
Returns:
The highest number presented
- Type
- Number
(static) meanOf(arg) → {Number}
Returns the mean/average value in a list of arguments OR an array
Parameters:
Name | Type | Description |
---|---|---|
arg |
Number | Array | Comma seperated list of numbers OR an Array of numbers |
Throws:
Console warning when nothing passed in. 0 (zero) returned
Returns:
The average value
- Type
- Number
(static) minOf(arg) → {Number}
Returns the lowest value in a list of arguments OR an array
Similar to Math.min() but works when passed an array of numbers
Parameters:
Name | Type | Description |
---|---|---|
arg |
Number | Array | Comma seperated list of numbers OR an Array of numbers |
Throws:
Console warning when nothing passed in. 0 (zero) returned
Returns:
The lowest number presented
- Type
- Number
(static) normalOf() → {MC.Point}
Returns a NEW normalised vector (point) of what was passed in
N.B to normalise the original vector itself use Point.normalise() instead
Parameters:
Type | Description |
---|---|
MC.Point | the vector |
Throws:
Console warning if parameter does not have x and y properties. Input parameter is returned.
Returns:
A new normalised vector
- Type
- MC.Point
(static) radToDeg(angle) → {Number}
Radian to Degree convertion
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number | Angle in Radians |
Returns:
Angle in Degrees
- Type
- Number
(static) randBetween(min, max) → {Number}
Returns a Random Integer between the provided values (inclusive)
Parameters:
Name | Type | Description |
---|---|---|
min |
Number | Mimimum value for the random number |
max |
Number | Maximum value for the random number |
Returns:
A Random Integer within the required range
- Type
- Number
(static) range(x1_or_pnt1, y1_or_pnt2, x2opt, y2opt) → {Number}
Returns the scalar distance between two points
Points can be entered in either (Point1,Point2) OR (x1,y1,x2,y2) format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x1_or_pnt1 |
Number | MC.Point | First Point OR first point's x value | |
y1_or_pnt2 |
Number | MC.Point | Second Point OR first point's y value | |
x2 |
Number |
<optional> |
Second point's x value |
y2 |
Number |
<optional> |
Second point's y value |
Throws:
Console warning if neither 2 nor 4 arguments presented. 0 (zero) returned
Returns:
the range between the points
- Type
- Number
(static) rangeSqr(x1_or_pnt1, y1_or_pnt2, x2opt, y2opt) → {Number}
Returns the scalar distance SQUARED between two points
Much more efficient for Hit Calculation purposes
Points can be entered in either (Point1,Point2) OR (x1,y1,x2,y2) format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x1_or_pnt1 |
Number | MC.Point | First Point OR first point's x value | |
y1_or_pnt2 |
Number | MC.Point | Second Point OR first point's y value | |
x2 |
Number |
<optional> |
Second point's x value |
y2 |
Number |
<optional> |
Second point's y value |
Throws:
Console warning if neither 2 nor 4 arguments presented. 0 (zero) returned
Returns:
the range squared between the points
- Type
- Number
(static) toHex() → {string}
Parameters:
Type | Description |
---|---|
Number | returns a minimum 2 length HEX number.
Used internally to convert Color values from rgb to Hex notation |
Returns:
- Type
- string