Math

external object Math(source)

Math functions.

See also

Properties

Link copied to clipboard

The number of degrees in a radian.

Link copied to clipboard
Link copied to clipboard

0.0000000001

Link copied to clipboard

0.00000000001

Link copied to clipboard

0.000000000001

Link copied to clipboard

0.0000000000001

Link copied to clipboard

0.00000000000001

Link copied to clipboard

0.000000000000001

Link copied to clipboard

0.0000000000000001

Link copied to clipboard

0.00000000000000001

Link copied to clipboard

0.000000000000000001

Link copied to clipboard

0.0000000000000000001

Link copied to clipboard

0.01

Link copied to clipboard

0.00000000000000000001

Link copied to clipboard

0.000000000000000000001

Link copied to clipboard

0.001

Link copied to clipboard

0.0001

Link copied to clipboard

0.00001

Link copied to clipboard

0.000001

Link copied to clipboard

0.0000001

Link copied to clipboard

0.00000001

Link copied to clipboard

0.000000001

Link copied to clipboard

4 * 1024 * 1024 * 1024

Link copied to clipboard

The gravitational parameter of the Earth in meters cubed per second squared as defined by the WGS84 model: 3.986004418e14

Link copied to clipboard

The mean radius of the moon, according to the "Report of the IAU/IAG Working Group on Cartographic Coordinates and Rotational Elements of the Planets and satellites: 2000", Celestial Mechanics 82: 83-110, 2002.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val PI: Double

pi

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The number of radians in an arc second.

Link copied to clipboard

The number of radians in a degree.

Link copied to clipboard
Link copied to clipboard

Radius of the sun in meters: 6.955e8

Link copied to clipboard
Link copied to clipboard

2pi

Functions

Link copied to clipboard

Computes Math.acos(value), but first clamps value to the range -1.0, 1.0 so that the function will never return NaN.

Link copied to clipboard

Computes Math.asin(value), but first clamps value to the range -1.0, 1.0 so that the function will never return NaN.

Link copied to clipboard
fun cbrt(number: Double? = definedExternally): Double

Finds the cube root of a number. Returns NaN if number is not provided.

Link copied to clipboard
fun chordLength(angle: Double, radius: Double): Double

Finds the chord length between two points given the circle's radius and the angle between the points.

Link copied to clipboard
fun clamp(value: Double, min: Double, max: Double): Double

Constraint a value to lie between two values.

Link copied to clipboard

Convenience function that clamps a latitude value, in radians, to the range [-Math.PI/2, Math.PI/2). Useful for sanitizing data before use in objects requiring correct range.

Link copied to clipboard

Converts a longitude value, in radians, to the range [-Math.PI, Math.PI).

Link copied to clipboard
fun cosh(value: Double): Double

Returns the hyperbolic cosine of a number. The hyperbolic cosine of value is defined to be (ex + e-x)/2.0 where e is Euler's number, approximately 2.71828183.

Link copied to clipboard
fun equalsEpsilon(left: Double, right: Double, relativeEpsilon: Double? = definedExternally, absoluteEpsilon: Double? = definedExternally): Boolean

Determines if two values are equal using an absolute or relative tolerance test. This is useful to avoid problems due to roundoff error when comparing floating-point values directly. The values are first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed. Use this test if you are unsure of the magnitudes of left and right.

Link copied to clipboard
fun factorial(n: Int): Int

Computes the factorial of the provided number.

Link copied to clipboard

Computes a fast approximation of Atan for input in the range -1, 1.

Link copied to clipboard

Computes a fast approximation of Atan2(x, y) for arbitrary input scalars.

Link copied to clipboard
fun fromSNorm(value: Double, rangeMaximum: Double? = definedExternally): Double

Converts a SNORM value in the range 0, rangeMaximum to a scalar in the range -1.0, 1.0.

Link copied to clipboard
fun greaterThan(left: Double, right: Double, absoluteEpsilon: Double): Boolean

Determines if the left value is greater the right value. If the two values are within absoluteEpsilon of each other, they are considered equal and this function returns false.

Link copied to clipboard
fun greaterThanOrEquals(left: Double, right: Double, absoluteEpsilon: Double): Boolean

Determines if the left value is greater than or equal to the right value. If the two values are within absoluteEpsilon of each other, they are considered equal and this function returns true.

Link copied to clipboard
fun incrementWrap(n: Int? = definedExternally, maximumValue: Double? = definedExternally, minimumValue: Double? = definedExternally): Double

Increments a number with a wrapping to a minimum value if the number exceeds the maximum value.

Link copied to clipboard

Determines if a non-negative integer is a power of two. The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.

Link copied to clipboard
fun lerp(p: Double, q: Double, time: Double): Double

Computes the linear interpolation of two values.

Link copied to clipboard
fun lessThan(left: Double, right: Double, absoluteEpsilon: Double): Boolean

Determines if the left value is less than the right value. If the two values are within absoluteEpsilon of each other, they are considered equal and this function returns false.

Link copied to clipboard
fun lessThanOrEquals(left: Double, right: Double, absoluteEpsilon: Double): Boolean

Determines if the left value is less than or equal to the right value. If the two values are within absoluteEpsilon of each other, they are considered equal and this function returns true.

Link copied to clipboard
fun log2(number: Double): Double

Finds the base 2 logarithm of a number.

Link copied to clipboard
fun logBase(number: Double, base: Double): Double

Finds the logarithm of a number to a base.

Link copied to clipboard
fun mod(m: Int, n: Int): Int

The modulo operation that also works for negative dividends.

Link copied to clipboard

Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.

Link copied to clipboard

Computes the next power-of-two integer greater than or equal to the provided non-negative integer. The maximum allowed input is 2^31 due to 32-bit bitwise operator limitation in Javascript.

Link copied to clipboard

Generates a random floating point number in the range of [0.0, 1.0) using a Mersenne twister.

Link copied to clipboard
fun normalize(value: Double, rangeMinimum: Double, rangeMaximum: Double): Double

Converts a scalar value in the range rangeMinimum, rangeMaximum to a scalar in the range 0.0, 1.0

Link copied to clipboard

Computes the previous power-of-two integer less than or equal to the provided non-negative integer. The maximum allowed input is (2^32)-1 due to 32-bit bitwise operator limitation in Javascript.

Link copied to clipboard

Generates a random number between two numbers.

Link copied to clipboard

Sets the seed used by the random number generator in Math.nextRandomNumber.

Link copied to clipboard
fun sign(value: Double): Double

Returns the sign of the value; 1 if the value is positive, -1 if the value is negative, or 0 if the value is 0.

Link copied to clipboard

Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. This is similar to Math.sign except that returns 1.0 instead of 0.0 when the input value is 0.0.

Link copied to clipboard
fun sinh(value: Double): Double

Returns the hyperbolic sine of a number. The hyperbolic sine of value is defined to be (ex - e-x)/2.0 where e is Euler's number, approximately 2.71828183.

Link copied to clipboard
fun toDegrees(radians: Double): Double

Converts radians to degrees.

Link copied to clipboard
fun toRadians(degrees: Double): Double

Converts degrees to radians.

Link copied to clipboard
fun toSNorm(value: Double, rangeMaximum: Double? = definedExternally): Double

Converts a scalar value in the range -1.0, 1.0 to a SNORM in the range 0, rangeMaximum

Link copied to clipboard

Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.