Maths

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.

Members

(static, readonly) DEG_TO_RAD :number

Constant to multiply by to convert from degrees to radians.

Type:
  • number

(static, readonly) EXP :number

The value of e. Same as Math.E

Type:
  • number

(static, readonly) METER_TO_PIXEL :number

Constatnt to multiply by to convert Meter to Pixel.

Type:
  • number

(static, readonly) PI :number

The Value of PI. Same as Math.PI

Type:
  • number

(static, readonly) PIXEL_TO_METER :number

Constant to multiply by to convert from Pixel to Meter.

Type:
  • number

(static, readonly) RAD_TO_DEG :number

Constant to multiply by to convert from radians to degrees.

Type:
  • number

(static, readonly) VERY_LARGE_NUMBER :number

Very large number. This number is in meters. It is used in physics for aproximate equality.

Type:
  • number

(static, readonly) VERY_SMALL_NUMBER :number

Very small number. This number is in meters. It is used in physics for aproximate equality.

Type:
  • number

Methods

(static) Clamp(value, min, max) → {number}

Clamp a number between a min and max value.

Parameters:
NameTypeDescription
valuenumber
minnumber
maxnumber
Returns:
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.

Parameters:
NameTypeDescription
vector1Vector2
vector2Vector2
Returns:
Type: 
number

(static) Distance(vector1, vector2) → {number}

Find the distance between two points.

Parameters:
NameTypeDescription
vector1Vector2
vector2Vector2
Returns:
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.

Parameters:
NameTypeDescription
vector1Vector2
vector2Vector2
Returns:
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.

Parameters:
NameTypeDescription
vector1Vector2
vector2Vector2
Returns:
Type: 
number

(static) Lenght(vector) → {number}

Find the lenght of a vector.

Parameters:
NameTypeDescription
vectorVector2
Returns:
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.

Parameters:
NameTypeDescription
vectorVector2
Returns:
Type: 
number

(static) MeterToPixel(meter) → {number}

Convert Meter to Pixel.

Parameters:
NameTypeDescription
meternumber
Returns:
Type: 
number

(static) MeterToPixelVector2(meter) → {Vector2}

Convert Vector2 from Meter to Pixel.

Parameters:
NameTypeDescription
meterVector2
Returns:
Type: 
Vector2

(static) NearlyEqual(a, b) → {boolean}

Find if two numbers /Vectors are approximately equal.

Parameters:
NameTypeDescription
anumber

can be a number or a Vector2.

bnumber

can be a number or a Vector2.

Returns:
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.

Parameters:
NameTypeDescription
vectorVector2
Returns:
Type: 
Vector2

(static) Perpendicular(vector) → {Vector2}

Find perpendicular vector. The perpendicular vector is 90 degrees to the original vector.

Parameters:
NameTypeDescription
vectorVector2
Returns:
Type: 
Vector2

(static) PixelToMeter(pixel) → {number}

Convert Pixel to Meter.

Parameters:
NameTypeDescription
pixelnumber
Returns:
Type: 
number

(static) PixelToMeterVector2(pixel) → {Vector2}

Convert Vector2 from Pixel to Meter.

Parameters:
NameTypeDescription
pixelVector2
Returns:
Type: 
Vector2

(static) RandomVector2(min, max) → {Vector2}

Get a random Vector2 between min and max.

Parameters:
NameTypeDescription
minVector2

The minimum value of the random vector.

maxVector2

The maximum value of the random vector.

Returns:
  • A random vector between min and max.
Type: 
Vector2