new Maths()
A Math class containing useful math functions. This class contains all the Mathamatical functions used by the engine. This class is static and should not be instantiated.
- Source
Members
(static, readonly) DEG_TO_RAD :number
Constant to multiply by to convert from degrees to radians.
- number
- Source
(static, readonly) EXP :number
The value of e. Same as Math.E
- number
- Source
(static, readonly) METER_TO_PIXEL :number
Constatnt to multiply by to convert Meter to Pixel.
- number
- Source
(static, readonly) PI :number
The Value of PI. Same as Math.PI
- number
- Source
(static, readonly) PIXEL_TO_METER :number
Constant to multiply by to convert from Pixel to Meter.
- number
- Source
(static, readonly) RAD_TO_DEG :number
Constant to multiply by to convert from radians to degrees.
- number
- Source
(static, readonly) VERY_LARGE_NUMBER :number
Very large number. This number is in meters. It is used in physics for aproximate equality.
- number
- Source
(static, readonly) VERY_SMALL_NUMBER :number
Very small number. This number is in meters. It is used in physics for aproximate equality.
- number
- Source
Methods
(static) Clamp(value, min, max) → {number}
Clamp a number between a min and max value.
Name | Type | Description |
---|---|---|
value | number | |
min | number | |
max | number |
- Source
- Type:
- number
(static) Cross(vector1, vector2) → {number}
Find the cross product of two vectors. The cross product is the determinant of the two vectors. It is the lenght projection of one vector onto the perpendicular of the other.
- Source
- Type:
- number
(static) Distance(vector1, vector2) → {number}
Find the distance between two points.
- Source
- Type:
- number
(static) DistanceSq(vector1, vector2) → {number}
Find the distance between two points squared. Finding Square root is expensive. To compare distances, it is better to compare the square of the distances.
- Source
- Type:
- number
(static) Dot(vector1, vector2) → {number}
Find the dot product of two vectors. The dot product is the sum of the products of the corresponding components of the two vectors. It is the lenght projection of one vector onto the other.
- Source
- Type:
- number
(static) Lenght(vector) → {number}
Find the lenght of a vector.
Name | Type | Description |
---|---|---|
vector | Vector2 |
- Source
- Type:
- number
(static) LenghtSq(vector) → {number}
Find the lenght of a vector squared. Finding Square root is expensive. To compare lenghts, it is better to compare the square of the lenghts.
Name | Type | Description |
---|---|---|
vector | Vector2 |
- Source
- Type:
- number
(static) MeterToPixel(meter) → {number}
Convert Meter to Pixel.
Name | Type | Description |
---|---|---|
meter | number |
- Source
- Type:
- number
(static) MeterToPixelVector2(meter) → {Vector2}
Convert Vector2 from Meter to Pixel.
Name | Type | Description |
---|---|---|
meter | Vector2 |
- Source
- Type:
- Vector2
(static) NearlyEqual(a, b) → {boolean}
Find if two numbers /Vectors are approximately equal.
Name | Type | Description |
---|---|---|
a | number | can be a number or a Vector2. |
b | number | can be a number or a Vector2. |
- Source
- Type:
- boolean
(static) Normalize(vector) → {Vector2}
Normalize a vector. A normalized vector has a lenght of 1, but the same direction as the original vector.
Name | Type | Description |
---|---|---|
vector | Vector2 |
- Source
- Type:
- Vector2
(static) Perpendicular(vector) → {Vector2}
Find perpendicular vector. The perpendicular vector is 90 degrees to the original vector.
Name | Type | Description |
---|---|---|
vector | Vector2 |
- Source
- Type:
- Vector2
(static) PixelToMeter(pixel) → {number}
Convert Pixel to Meter.
Name | Type | Description |
---|---|---|
pixel | number |
- Source
- Type:
- number
(static) PixelToMeterVector2(pixel) → {Vector2}
Convert Vector2 from Pixel to Meter.
Name | Type | Description |
---|---|---|
pixel | Vector2 |
- Source
- Type:
- Vector2
(static) RandomVector2(min, max) → {Vector2}
Get a random Vector2 between min and max.
Name | Type | Description |
---|---|---|
min | Vector2 | The minimum value of the random vector. |
max | Vector2 | The maximum value of the random vector. |
- Source
- A random vector between min and max.
- Type:
- Vector2