Members
The number of degrees in a radian.
0.1
0.01
0.001
0.0001
0.00001
0.000001
0.0000001
0.00000001
0.000000001
0.0000000001
0.00000000001
0.000000000001
0.0000000000001
0.00000000000001
0.000000000000001
0.0000000000000001
0.00000000000000001
0.000000000000000001
0.0000000000000000001
0.00000000000000000001
0.000000000000000000001
4 * 1024 * 1024 * 1024
The gravitational parameter of the Earth in meters cubed
per second squared as defined by the WGS84 model: 3.986004418e14
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.
1/pi
1/2pi
pi
pi/4
pi/6
pi/3
pi/2
The number of radians in an arc second.
The number of radians in a degree.
64 * 1024
Radius of the sun in meters: 6.955e8
3pi/2
2pi
Methods
Computes
Math.acos(value)
, but first clamps value
to the range [-1.0, 1.0]
so that the function will never return NaN.
Name | Type | Description |
---|---|---|
value |
Number | The value for which to compute acos. |
Returns:
The acos of the value if the value is in the range [-1.0, 1.0], or the acos of -1.0 or 1.0,
whichever is closer, if the value is outside the range.
Computes
Math.asin(value)
, but first clamps value
to the range [-1.0, 1.0]
so that the function will never return NaN.
Name | Type | Description |
---|---|---|
value |
Number | The value for which to compute asin. |
Returns:
The asin of the value if the value is in the range [-1.0, 1.0], or the asin of -1.0 or 1.0,
whichever is closer, if the value is outside the range.
Finds the cube root of a number.
Returns NaN if
number
is not provided.
Name | Type | Description |
---|---|---|
number |
Number | optional The number. |
Returns:
The result.
Finds the chord length between two points given the circle's radius and the angle between the points.
Name | Type | Description |
---|---|---|
angle |
Number | The angle between the two points. |
radius |
Number | The radius of the circle. |
Returns:
The chord length.
Constraint a value to lie between two values.
Name | Type | Description |
---|---|---|
value |
Number | The value to constrain. |
min |
Number | The minimum value. |
max |
Number | The maximum value. |
Returns:
The value clamped so that min <= value <= max.
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.
Name | Type | Description |
---|---|---|
angle |
Number |
The latitude value, in radians, to clamp to the range [-Math.PI/2 , Math.PI/2 ). |
Returns:
The latitude value clamped to the range [
-Math.PI/2
, Math.PI/2
).
Example:
// Clamp 108 degrees latitude to 90 degrees latitude
var latitude = LSGlobe.Math.clampToLatitudeRange(LSGlobe.Math.toRadians(108.0));
Converts a longitude value, in radians, to the range [
-Math.PI
, Math.PI
).
Name | Type | Description |
---|---|---|
angle |
Number |
The longitude value, in radians, to convert to the range [-Math.PI , Math.PI ). |
Returns:
The equivalent longitude value in the range [
-Math.PI
, Math.PI
).
Example:
// Convert 270 degrees to -90 degrees longitude
var longitude = LSGlobe.Math.convertLongitudeRange(LSGlobe.Math.toRadians(270.0));
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.
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is positive infinity.
- If the argument is zero, then the result is 1.0.
Name | Type | Description |
---|---|---|
value |
Number | The number whose hyperbolic cosine is to be returned. |
Returns:
The hyperbolic cosine of
value
.
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.
Name | Type | Default | Description |
---|---|---|---|
left |
Number | The first value to compare. | |
right |
Number | The other value to compare. | |
relativeEpsilon |
Number |
0
|
optional
The maximum inclusive delta between left and right for the relative tolerance test. |
absoluteEpsilon |
Number |
relativeEpsilon
|
optional
The maximum inclusive delta between left and right for the absolute tolerance test. |
Returns:
true
if the values are equal within the epsilon; otherwise, false
.
Example:
var a = LSGlobe.Math.equalsEpsilon(0.0, 0.01, LSGlobe.Math.EPSILON2); // true
var b = LSGlobe.Math.equalsEpsilon(0.0, 0.1, LSGlobe.Math.EPSILON2); // false
var c = LSGlobe.Math.equalsEpsilon(3699175.1634344, 3699175.2, LSGlobe.Math.EPSILON7); // true
var d = LSGlobe.Math.equalsEpsilon(3699175.1634344, 3699175.2, LSGlobe.Math.EPSILON9); // false
Computes the factorial of the provided number.
Name | Type | Description |
---|---|---|
n |
Number | The number whose factorial is to be computed. |
Returns:
The factorial of the provided number or undefined if the number is less than 0.
Throws:
-
DeveloperError : A number greater than or equal to 0 is required.
Example:
//Compute 7!, which is equal to 5040
var computedFactorial = LSGlobe.Math.factorial(7);
See:
Computes a fast approximation of Atan for input in the range [-1, 1].
Based on Michal Drobot's approximation from ShaderFastLibs,
which in turn is based on "Efficient approximations for the arctangent function,"
Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006.
Adapted from ShaderFastLibs under MIT License.
Name | Type | Description |
---|---|---|
x |
Number | An input number in the range [-1, 1] |
Returns:
An approximation of atan(x)
Computes a fast approximation of Atan2(x, y) for arbitrary input scalars.
Range reduction math based on nvidia's cg reference implementation: http://developer.download.nvidia.com/cg/atan2.html
Name | Type | Description |
---|---|---|
x |
Number | An input number that isn't zero if y is zero. |
y |
Number | An input number that isn't zero if x is zero. |
Returns:
An approximation of atan2(x, y)
Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].
Name | Type | Default | Description |
---|---|---|---|
value |
Number | SNORM value in the range [0, rangeMaximum] | |
rangeMaximum |
Number |
255
|
optional The maximum value in the SNORM range, 255 by default. |
Returns:
Scalar in the range [-1.0, 1.0].
- CesiumMath.toSNorm
See:
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.
Name | Type | Description |
---|---|---|
left |
Number | The first number to compare. |
right |
Number | The second number to compare. |
absoluteEpsilon |
Number | The absolute epsilon to use in comparison. |
Returns:
true
if left
is greater than right
by more than
absoluteEpsilon. false
if left
is less or if the two
values are nearly equal.
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.
Name | Type | Description |
---|---|---|
left |
Number | The first number to compare. |
right |
Number | The second number to compare. |
absoluteEpsilon |
Number | The absolute epsilon to use in comparison. |
Returns:
true
if left
is greater than right
or if the
the values are nearly equal.
Increments a number with a wrapping to a minimum value if the number exceeds the maximum value.
Name | Type | Default | Description |
---|---|---|---|
n |
Number | optional The number to be incremented. | |
maximumValue |
Number | optional The maximum incremented value before rolling over to the minimum value. | |
minimumValue |
Number |
0.0
|
optional The number reset to after the maximum value has been exceeded. |
Returns:
The incremented number.
Throws:
-
DeveloperError : Maximum value must be greater than minimum value.
Example:
var n = LSGlobe.Math.incrementWrap(5, 10, 0); // returns 6
var n = LSGlobe.Math.incrementWrap(10, 10, 0); // returns 0
Determines if a positive integer is a power of two.
Name | Type | Description |
---|---|---|
n |
Number | The positive integer to test. |
Returns:
true
if the number if a power of two; otherwise, false
.
Throws:
-
DeveloperError : A number greater than or equal to 0 is required.
Example:
var t = LSGlobe.Math.isPowerOfTwo(16); // true
var f = LSGlobe.Math.isPowerOfTwo(20); // false
Computes the linear interpolation of two values.
Name | Type | Description |
---|---|---|
p |
Number | The start value to interpolate. |
q |
Number | The end value to interpolate. |
time |
Number |
The time of interpolation generally in the range [0.0, 1.0] . |
Returns:
The linearly interpolated value.
Example:
var n = LSGlobe.Math.lerp(0.0, 2.0, 0.5); // returns 1.0
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.
Name | Type | Description |
---|---|---|
left |
Number | The first number to compare. |
right |
Number | The second number to compare. |
absoluteEpsilon |
Number | The absolute epsilon to use in comparison. |
Returns:
true
if left
is less than right
by more than
absoluteEpsilon. false
if left
is greater or if the two
values are nearly equal.
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.
Name | Type | Description |
---|---|---|
left |
Number | The first number to compare. |
right |
Number | The second number to compare. |
absoluteEpsilon |
Number | The absolute epsilon to use in comparison. |
Returns:
true
if left
is less than right
or if the
the values are nearly equal.
Finds the base 2 logarithm of a number.
Name | Type | Description |
---|---|---|
number |
Number | The number. |
Returns:
The result.
Finds the logarithm of a number to a base.
Name | Type | Description |
---|---|---|
number |
Number | The number. |
base |
Number | The base. |
Returns:
The result.
The modulo operation that also works for negative dividends.
Name | Type | Description |
---|---|---|
m |
Number | The dividend. |
n |
Number | The divisor. |
Returns:
The remainder.
Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
Name | Type | Description |
---|---|---|
angle |
Number | in radians |
Returns:
The angle in the range [
-CesiumMath.PI
, CesiumMath.PI
].
Computes the next power-of-two integer greater than or equal to the provided positive integer.
Name | Type | Description |
---|---|---|
n |
Number | The positive integer to test. |
Returns:
The next power-of-two integer.
Throws:
-
DeveloperError : A number greater than or equal to 0 is required.
Example:
var n = LSGlobe.Math.nextPowerOfTwo(29); // 32
var m = LSGlobe.Math.nextPowerOfTwo(32); // 32
Generates a random floating point number in the range of [0.0, 1.0)
using a Mersenne twister.
Returns:
A random number in the range of [0.0, 1.0).
- CesiumMath.setRandomNumberSeed
- Mersenne twister on Wikipedia
See:
Converts a scalar value in the range [rangeMinimum, rangeMaximum] to a scalar in the range [0.0, 1.0]
Name | Type | Description |
---|---|---|
value |
Number | The scalar value in the range [rangeMinimum, rangeMaximum] |
rangeMinimum |
Number | The minimum value in the mapped range. |
rangeMaximum |
Number | The maximum value in the mapped range. |
Returns:
A scalar value, where rangeMinimum maps to 0.0 and rangeMaximum maps to 1.0.
Generates a random number between two numbers.
Name | Type | Description |
---|---|---|
min |
Number | The minimum value. |
max |
Number | The maximum value. |
Returns:
A random number between the min and max.
Sets the seed used by the random number generator
in
CesiumMath#nextRandomNumber
.
Name | Type | Description |
---|---|---|
seed |
Number | An integer used as the seed. |
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.
Name | Type | Description |
---|---|---|
value |
Number | The value to return the sign of. |
Returns:
The sign of value.
Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative.
This is similar to
CesiumMath#sign
except that returns 1.0 instead of
0.0 when the input value is 0.0.
Name | Type | Description |
---|---|---|
value |
Number | The value to return the sign of. |
Returns:
The sign of value.
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.
Special cases:
- If the argument is NaN, then the result is NaN.
- If the argument is infinite, then the result is an infinity with the same sign as the argument.
- If the argument is zero, then the result is a zero with the same sign as the argument.
Name | Type | Description |
---|---|---|
value |
Number | The number whose hyperbolic sine is to be returned. |
Returns:
The hyperbolic sine of
value
.
Converts radians to degrees.
Name | Type | Description |
---|---|---|
radians |
Number | The angle to convert in radians. |
Returns:
The corresponding angle in degrees.
Converts degrees to radians.
Name | Type | Description |
---|---|---|
degrees |
Number | The angle to convert in degrees. |
Returns:
The corresponding angle in radians.
Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum]
Name | Type | Default | Description |
---|---|---|---|
value |
Number | The scalar value in the range [-1.0, 1.0] | |
rangeMaximum |
Number |
255
|
optional The maximum value in the mapped range, 255 by default. |
Returns:
A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.
- CesiumMath.fromSNorm
See:
Produces an angle in the range 0 <= angle <= 2Pi which is equivalent to the provided angle.
Name | Type | Description |
---|---|---|
angle |
Number | in radians |
Returns:
The angle in the range [0,
CesiumMath.TWO_PI
].