# CesiumMath

#### CesiumMath()
Core/Math.js 19

  Math functions.

### Members

#### staticconstantCesium.CesiumMath.DEGREES_PER_RADIAN : Number
Core/Math.js 403

  The number of degrees in a radian.
  Default Value: `180.0 / Math.PI`

#### staticconstantCesium.CesiumMath.EPSILON1 : Number
Core/Math.js 26

  0.1

#### staticconstantCesium.CesiumMath.EPSILON2 : Number
Core/Math.js 33

  0.01

#### staticconstantCesium.CesiumMath.EPSILON3 : Number
Core/Math.js 40

  0.001

#### staticconstantCesium.CesiumMath.EPSILON4 : Number
Core/Math.js 47

  0.0001

#### staticconstantCesium.CesiumMath.EPSILON5 : Number
Core/Math.js 54

  0.00001

#### staticconstantCesium.CesiumMath.EPSILON6 : Number
Core/Math.js 61

  0.000001

#### staticconstantCesium.CesiumMath.EPSILON7 : Number
Core/Math.js 68

  0.0000001

#### staticconstantCesium.CesiumMath.EPSILON8 : Number
Core/Math.js 75

  0.00000001

#### staticconstantCesium.CesiumMath.EPSILON9 : Number
Core/Math.js 82

  0.000000001

#### staticconstantCesium.CesiumMath.EPSILON10 : Number
Core/Math.js 89

  0.0000000001

#### staticconstantCesium.CesiumMath.EPSILON11 : Number
Core/Math.js 96

  0.00000000001

#### staticconstantCesium.CesiumMath.EPSILON12 : Number
Core/Math.js 103

  0.000000000001

#### staticconstantCesium.CesiumMath.EPSILON13 : Number
Core/Math.js 110

  0.0000000000001

#### staticconstantCesium.CesiumMath.EPSILON14 : Number
Core/Math.js 117

  0.00000000000001

#### staticconstantCesium.CesiumMath.EPSILON15 : Number
Core/Math.js 124

  0.000000000000001

#### staticconstantCesium.CesiumMath.EPSILON16 : Number
Core/Math.js 131

  0.0000000000000001

#### staticconstantCesium.CesiumMath.EPSILON17 : Number
Core/Math.js 138

  0.00000000000000001

#### staticconstantCesium.CesiumMath.EPSILON18 : Number
Core/Math.js 145

  0.000000000000000001

#### staticconstantCesium.CesiumMath.EPSILON19 : Number
Core/Math.js 152

  0.0000000000000000001

#### staticconstantCesium.CesiumMath.EPSILON20 : Number
Core/Math.js 159

  0.00000000000000000001

#### staticconstantCesium.CesiumMath.GRAVITATIONALPARAMETER : Number
Core/Math.js 166

  3.986004418e14

#### staticconstantCesium.CesiumMath.LUNAR_RADIUS : Number
Core/Math.js 182

  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.

#### staticconstantCesium.CesiumMath.ONE_OVER_PI : Number
Core/Math.js 329

  1/pi

#### staticconstantCesium.CesiumMath.ONE_OVER_TWO_PI : Number
Core/Math.js 385

  1/2pi

#### staticconstantCesium.CesiumMath.PI : Number
Core/Math.js 321

  pi

#### staticconstantCesium.CesiumMath.PI_OVER_FOUR : Number
Core/Math.js 353

  pi/4

#### staticconstantCesium.CesiumMath.PI_OVER_SIX : Number
Core/Math.js 361

  pi/6

#### staticconstantCesium.CesiumMath.PI_OVER_THREE : Number
Core/Math.js 345

  pi/3

#### staticconstantCesium.CesiumMath.PI_OVER_TWO : Number
Core/Math.js 337

  pi/2

#### staticconstantCesium.CesiumMath.RADIANS_PER_ARCSECOND : Number
Core/Math.js 412

  The number of radians in an arc second.
  Default Value: ``CesiumMath.RADIANS_PER_DEGREE` / 3600.0`

#### staticconstantCesium.CesiumMath.RADIANS_PER_DEGREE : Number
Core/Math.js 394

  The number of radians in a degree.
  Default Value: `Math.PI / 180.0`

#### staticconstantCesium.CesiumMath.SIXTY_FOUR_KILOBYTES : Number
Core/Math.js 189

  64 * 1024

#### staticconstantCesium.CesiumMath.SOLAR_RADIUS : Number
Core/Math.js 173

  Radius of the sun in meters: 6.955e8

#### staticconstantCesium.CesiumMath.THREE_PI_OVER_TWO : Number
Core/Math.js 369

  3pi/2

#### staticconstantCesium.CesiumMath.TWO_PI : Number
Core/Math.js 377

  2pi

### Methods

#### staticCesium.CesiumMath.acosClamped(value) → Number
Core/Math.js 763

  Computes `Math.acos(value)</acode>, 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.

#### staticCesium.CesiumMath.asinClamped(value) → Number
Core/Math.js 780

  Computes `Math.asin(value)</acode>, 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.

#### staticCesium.CesiumMath.chordLength(angle, radius) → Number
Core/Math.js 796

  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.

#### staticCesium.CesiumMath.clamp(value, min, max) → Number
Core/Math.js 709

  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.

#### staticCesium.CesiumMath.clampToLatitudeRange(angle) → Number
Core/Math.js 483

  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 = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));

#### staticCesium.CesiumMath.convertLongitudeRange(angle) → Number
Core/Math.js 452

  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 = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));

#### staticCesium.CesiumMath.cosh(value) → Number
Core/Math.js 293

  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`.

#### staticCesium.CesiumMath.equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) → Boolean
Core/Math.js 564

  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 |  | 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 = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
      var b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2);  // false
      var c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true
      var d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false

#### staticCesium.CesiumMath.factorial(n) → Number
Core/Math.js 598

  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 = Cesium.Math.factorial(7);

  ##### See:

  - Factorial on Wikipedia

#### staticCesium.CesiumMath.fromSNorm(value, rangeMax) → Number
Core/Math.js 241

  Converts a SNORM value in the range [0, rangeMax] to a scalar in the range [-1.0, 1.0].

  Name | Type | Default | Description
  --- | --- | --- | ---
  `value` | Number |  | SNORM value in the range [0, 255]
  `rangeMax` | Number | `255` | optional The maximum value in the SNORM range, 255 by default.

  ##### Returns:

  Scalar in the range [-1.0, 1.0].

  ##### See:

  - CesiumMath.toSNorm

#### staticCesium.CesiumMath.incrementWrap(n, maximumValue, minimumValue) → Number
Core/Math.js 629

  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 = Cesium.Math.incrementWrap(5, 10, 0); // returns 6
      var n = Cesium.Math.incrementWrap(10, 10, 0); // returns 0

#### staticCesium.CesiumMath.isPowerOfTwo(n) → Boolean
Core/Math.js 660

  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 = Cesium.Math.isPowerOfTwo(16); // true
      var f = Cesium.Math.isPowerOfTwo(20); // false

#### staticCesium.CesiumMath.lerp(p, q, time) → Number
Core/Math.js 311

  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 = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0

#### staticCesium.CesiumMath.logBase(number, base) → Number
Core/Math.js 815

  Finds the logarithm of a number to a base.

  Name | Type | Description
  --- | --- | ---
  `number` | Number | The number.
  `base` | Number | The base.

  ##### Returns:

  The result.

#### staticCesium.CesiumMath.mod(m, n) → Number
Core/Math.js 534

  The modulo operation that also works for negative dividends.

  Name | Type | Description
  --- | --- | ---
  `m` | Number | The dividend.
  `n` | Number | The divisor.

  ##### Returns:

  The remainder.

#### staticCesium.CesiumMath.negativePiToPi(angle) → Number
Core/Math.js 499

  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`].

#### staticCesium.CesiumMath.nextPowerOfTwo(n) → Number
Core/Math.js 682

  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 = Cesium.Math.nextPowerOfTwo(29); // 32
      var m = Cesium.Math.nextPowerOfTwo(32); // 32

#### staticCesium.CesiumMath.nextRandomNumber() → Number
Core/Math.js 751

  Generates a random 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).

  ##### See:

  - CesiumMath.setRandomNumberSeed
  - Mersenne twister on Wikipedia

#### staticCesium.CesiumMath.setRandomNumberSeed(seed)
Core/Math.js 732

  Sets the seed used by the random number generator in `CesiumMath#nextRandomNumber`.

  Name | Type | Description
  --- | --- | ---
  `seed` | Number | An integer used as the seed.

#### staticCesium.CesiumMath.sign(value) → Number
Core/Math.js 198

  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.

#### staticCesium.CesiumMath.signNotZero(value) → Number
Core/Math.js 216

  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.

#### staticCesium.CesiumMath.sinh(value) → Number
Core/Math.js 267

  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`.

#### staticCesium.CesiumMath.toDegrees(radians) → Number
Core/Math.js 433

  Converts radians to degrees.

  Name | Type | Description
  --- | --- | ---
  `radians` | Number | The angle to convert in radians.

  ##### Returns:

  The corresponding angle in degrees.

#### staticCesium.CesiumMath.toRadians(degrees) → Number
Core/Math.js 419

  Converts degrees to radians.

  Name | Type | Description
  --- | --- | ---
  `degrees` | Number | The angle to convert in degrees.

  ##### Returns:

  The corresponding angle in radians.

#### staticCesium.CesiumMath.toSNorm(value, rangeMax) → Number
Core/Math.js 228

  Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMax]

  Name | Type | Default | Description
  --- | --- | --- | ---
  `value` | Number |  | The scalar value in the range [-1.0, 1.0]
  `rangeMax` | Number | `255` | optional The maximum value in the mapped range, 255 by default.

  ##### Returns:

  A SNORM value, where 0 maps to -1.0 and rangeMax maps to 1.0.

  ##### See:

  - CesiumMath.fromSNorm

#### staticCesium.CesiumMath.zeroToTwoPi(angle) → Number
Core/Math.js 514

  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`].