Shaku

Shaku JS

Back To Table of Content

Math Helper

MathHelper

Implement some math utilities functions.

Kind: global class

MathHelper.PI2

PI * 2 value.

Kind: static property of MathHelper

MathHelper.lerp(start, end, amount) ⇒ Number

Perform linear interpolation between start and end values.

Kind: static method of MathHelper
Returns: Number - interpolated value between start and end.

Param Type Description
start Number Starting value.
end Number Ending value.
amount Number How much to interpolate from start to end.

MathHelper.dot(x1, y1, x2, y2) ⇒ Number

Calculate 2d dot product.

Kind: static method of MathHelper
Returns: Number - dot product result.

Param Type Description
x1 Number First vector x.
y1 Number First vector y.
x2 Number Second vector x.
y2 Number Second vector y.

MathHelper.roundToMultiple(numToRound, multiple) ⇒ Number

Make a number a multiply of another number by rounding it up.

Kind: static method of MathHelper
Returns: Number - Result number.

Param Type Description
numToRound Number Number to round up.
multiple Number Number to make ‘numToRound’ a multiply of.

MathHelper.toRadians(degrees) ⇒ Number

Convert degrees to radians.

Kind: static method of MathHelper
Returns: Number - Value as radians.

Param Type Description
degrees Number Degrees value to convert to radians.

MathHelper.toDegrees(radians) ⇒ Number

Convert radians to degrees.

Kind: static method of MathHelper
Returns: Number - Value as degrees.

Param Type Description
radians Number Radians value to convert to degrees.

MathHelper.radiansDistanceSigned(a1, a2) ⇒ Number

Find shortest distance between two radians, with sign (ie distance can be negative).

Kind: static method of MathHelper
Returns: Number - Shortest distance between radians.

Param Type Description
a1 Number First radian.
a2 Number Second radian.

MathHelper.radiansDistance(a1, a2) ⇒ Number

Find shortest distance between two radians.

Kind: static method of MathHelper
Returns: Number - Shortest distance between radians.

Param Type Description
a1 Number First radian.
a2 Number Second radian.

MathHelper.degreesDistanceSigned(a1, a2) ⇒ Number

Find shortest distance between two angles in degrees, with sign (ie distance can be negative).

Kind: static method of MathHelper
Returns: Number - Shortest distance between angles.

Param Type Description
a1 Number First angle.
a2 Number Second angle.

MathHelper.degreesDistance(a1, a2) ⇒ Number

Find shortest distance between two angles in degrees.

Kind: static method of MathHelper
Returns: Number - Shortest distance between angles.

Param Type Description
a1 Number First angle.
a2 Number Second angle.

MathHelper.lerpRadians(a1, a2, alpha) ⇒ Number

Perform linear interpolation between radian values. Unlike the regular lerp method, this method will take wrapping into consideration, and will always lerp via the shortest distance.

Kind: static method of MathHelper
Returns: Number - interpolated radians between start and end.

Param Type Description
a1 Number Starting value.
a2 Number Ending value.
alpha Number How much to interpolate from start to end.

MathHelper.lerpDegrees(a1, a2, alpha) ⇒ Number

Perform linear interpolation between degrees. Unlike the regular lerp method, this method will take wrapping into consideration, and will always lerp via the shortest distance.

Kind: static method of MathHelper
Returns: Number - interpolated degrees between start and end.

Param Type Description
a1 Number Starting value.
a2 Number Ending value.
alpha Number How much to interpolate from start to end.

MathHelper.round10(num) ⇒ Number

Round numbers from 10’th digit. This is useful for calculations that should return round or almost round numbers, but have a long tail of 0’s and 1 due to floating points accuracy.

Kind: static method of MathHelper
Returns: Number - Rounded number.

Param Type Description
num Number Number to round.

MathHelper.wrapDegrees(degrees) ⇒ Number

Wrap degrees value to be between 0 to 360.

Kind: static method of MathHelper
Returns: Number - degrees wrapped to be 0-360 values.

Param Type Description
degrees Number Degrees to wrap.

MathHelper.calculateNormal(v1, v2, v3) ⇒ Vector3

Calculate the normal vector of a polygon using 3 points on it.

Kind: static method of MathHelper
Returns: Vector3 - Normal vector, normalized.

Param Type Description
v1 Vector3 Vector on the polygon.
v2 Vector3 Vector on the polygon.
v3 Vector3 Vector on the polygon.