Math

数学函数。

Members

static constant Cesium.Math.DEGREES_PER_RADIAN : Number

以弧度为单位的度数。

static constant Cesium.Math.EPSILON1 : Number

0.1

static constant Cesium.Math.EPSILON2 : Number

0.01

static constant Cesium.Math.EPSILON3 : Number

0.001

static constant Cesium.Math.EPSILON4 : Number

0.0001

static constant Cesium.Math.EPSILON5 : Number

0.00001

static constant Cesium.Math.EPSILON6 : Number

0.000001

static constant Cesium.Math.EPSILON7 : Number

0.0000001

static constant Cesium.Math.EPSILON8 : Number

0.00000001

static constant Cesium.Math.EPSILON9 : Number

0.000000001

static constant Cesium.Math.EPSILON10 : Number

0.0000000001

static constant Cesium.Math.EPSILON11 : Number

0.00000000001

static constant Cesium.Math.EPSILON12 : Number

0.000000000001

static constant Cesium.Math.EPSILON13 : Number

0.0000000000001

static constant Cesium.Math.EPSILON14 : Number

0.00000000000001

static constant Cesium.Math.EPSILON15 : Number

0.000000000000001

static constant Cesium.Math.EPSILON16 : Number

0.00000000000000001

static constant Cesium.Math.EPSILON17 : Number

0.00000000000000001

static constant Cesium.Math.EPSILON18 : Number

0.000000000000000001

static constant Cesium.Math.EPSILON19 : Number

0.0000000000000000001

static constant Cesium.Math.EPSILON20 : Number

0.00000000000000000001

static constant Cesium.Math.EPSILON21 : Number

0.000000000000000000001

static constant Cesium.Math.FOUR_GIGABYTES : Number

4 * 1024 * 1024 * 1024

static constant Cesium.Math.GRAVITATIONALPARAMETER : Number

WGS84 模型定义的地球引力参数,以米立方/秒平方为单位:3.986004418e14

static constant Cesium.Math.LUNAR_RADIUS : Number

月球的平均半径,根据'IAU/IAG 工作组关于行星和卫星的制图坐标和旋转要素的报告:2000',Celestial Mechanics 82:83-110, 2002。

static constant Cesium.Math.ONE_OVER_PI : Number

1/pi

static constant Cesium.Math.ONE_OVER_TWO_PI : Number

1/2pi

static constant Cesium.Math.PI : Number

圆周率

static constant Cesium.Math.PI_OVER_FOUR : Number

pi/4

static constant Cesium.Math.PI_OVER_SIX : Number

pi/6

static constant Cesium.Math.PI_OVER_THREE : Number

pi/3

static constant Cesium.Math.PI_OVER_TWO : Number

pi/2

static constant Cesium.Math.RADIANS_PER_ARCSECOND : Number

弧秒内的弧度数。

static constant Cesium.Math.RADIANS_PER_DEGREE : Number

以度为单位的弧度数。

static constant Cesium.Math.SIXTY_FOUR_KILOBYTES : Number

64 * 1024

static constant Cesium.Math.SOLAR_RADIUS : Number

太阳半径以米为单位:6.955e8

static constant Cesium.Math.THREE_PI_OVER_TWO : Number

3pi/2

static constant Cesium.Math.TWO_PI : Number

2pi

Methods

static Cesium.Math.acosClamped (value) → Number

计算 Math.acos(value) ,但首先将 value 限制在 [-1.0, 1.0] 范围内,以便函数永远不会返回 NaN。
Name Type Description
value Number 计算 acos 的值。
Returns:
如果值在 [-1.0, 1.0] 范围内,则为该值的 acos,如果该值超出范围,则为 -1.0 或 1.0 的 acos,以更接近者为准。

static Cesium.Math.asinClamped (value) → Number

计算 Math.asin(value) ,但首先将 value 限制在 [-1.0, 1.0] 范围内,以便函数永远不会返回 NaN。
Name Type Description
value Number 要计算 asin 的值。
Returns:
如果值在 [-1.0, 1.0] 范围内,则为值的 asin,如果值超出范围,则为 -1.0 或 1.0 的 asin,以更接近者为准。

static Cesium.Math.cbrt ( number ) → Number

求一个数的立方根。如果未提供 number ,则返回 NaN。
Name Type Description
number Number 可选 号码。
Returns:
结果。

static Cesium.Math.chordLength (angle, radius) → Number

给定圆的半径和两点之间的角度,求两点之间的弦长。
Name Type Description
angle Number 两点之间的角度。
radius Number 圆的半径。
Returns:
弦长。

static Cesium.Math.clamp (value, min, max) → Number

将一个值限制在两个值之间。
Name Type Description
value Number 要钳位的值。
min Number 最小值。
max Number 最大值。
Returns:
限定值,使得 min <= result <= max。

static Cesium.Math.clampToLatitudeRange (angle) → Number

将纬度值(以弧度表示)限制在 [ -Math.PI/2 , Math.PI/2 )范围内的便利函数。在用于需要正确范围的对象之前对数据进行清理很有用。
Name Type Description
angle Number 以弧度为单位的纬度值,以限制在 [ -Math.PI/2 , Math.PI/2 ) 范围内。
Returns:
纬度值限制在 [ -Math.PI/2 , Math.PI/2 ) 范围内。
Example:
// Clamp 108 degrees latitude to 90 degrees latitude
const latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));

static Cesium.Math.convertLongitudeRange (angle) → Number

将经度值(以弧度表示)转换为范围 [ -Math.PI , Math.PI )。
Name Type Description
angle Number 要转换为范围 [ -Math.PI , Math.PI ) 的经度值(以弧度为单位)。
Returns:
[ -Math.PI , Math.PI ) 范围内的等效经度值。
Example:
// Convert 270 degrees to -90 degrees longitude
const longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));

static Cesium.Math.cosh (value) → Number

返回数字的双曲余弦。 值 的双曲余弦定义为 ( e x + e -x )/2.0,其中 e 是欧拉数,大约为 2.71828183。

特别案例:

  • 如果参数为 NaN,则结果为 NaN。
  • 如果参数是无限的,那么结果是正无穷大。
  • 如果参数为零,则结果为 1.0。
Name Type Description
value Number 要返回其双曲余弦的数字。
Returns:
value 的双曲余弦。

static Cesium.Math.equalsEpsilon (left, right, relativeEpsilon , absoluteEpsilon ) → Boolean

使用绝对或相对容差测试确定两个值是否相等。当直接比较浮点值时,这对于避免由于舍入误差引起的问题很有用。首先使用绝对容差测试比较这些值。如果失败,则执行相对容差测试。如果您不确定左右的大小,请使用此测试。
Name Type Default Description
left Number 要比较的第一个值。
right Number 要比较的另一个值。
relativeEpsilon Number 0 可选 相对容差测试的 left 之间 right 最大包含增量。
absoluteEpsilon Number relativeEpsilon 可选 绝对公差测试的 left 之间 right 最大包含增量。
Returns:
如果 epsilon 内的值相等,则为 true ;否则, false 。
Example:
const a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
const b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2);  // false
const c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true
const d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false

static Cesium.Math.factorial (n) → Number

计算所提供数字的阶乘。
Name Type Description
n Number 要计算其阶乘的数字。
Returns:
提供的数字的阶乘,如果数字小于 0,则为 undefined。
Throws:
Example:
//Compute 7!, which is equal to 5040
const computedFactorial = Cesium.Math.factorial(7);
See:

static Cesium.Math.fastApproximateAtan (x) → Number

为 [-1, 1] 范围内的输入计算 Atan 的快速近似值。基于 Michal Drobot 从 ShaderFastLibs 中的近似值,该近似值又基于'Efficient approximations for the arctangent function',Rajan, S. Sichun Wang Inkol, R. Joyal, A.,2006 年 5 月。根据 MIT 许可改编自 ShaderFastLibs。
Name Type Description
x Number [-1, 1] 范围内的输入数字
Returns:
atan(x) 的近似值

static Cesium.Math.fastApproximateAtan2 (x, y) → Number

计算任意输入标量的 Atan2(x, y) 的快速近似值。基于 nvidia 的 cg 参考实现的范围缩减数学:http://developer.download.nvidia.com/cg/atan2.html
Name Type Description
x Number 如果 y 为零,则输入数字不为零。
y Number 如果 x 为零,则输入数字不为零。
Returns:
atan2(x, y) 的近似值

static Cesium.Math.fromSNorm (value, rangeMaximum ) → Number

将 [0, rangeMaximum] 范围内的 SNORM 值转换为 [-1.0, 1.0] 范围内的标量。
Name Type Default Description
value Number [0, rangeMaximum] 范围内的 SNORM 值
rangeMaximum Number 255 可选 SNORM 范围内的最大值,默认为 255。
Returns:
范围 [-1.0, 1.0] 内的标量。
See:
  • CesiumMath.toSNorm

static Cesium.Math.greaterThan (left, right, absoluteEpsilon) → Boolean

确定左值是否大于右值。如果这两个值在彼此的 absoluteEpsilon 范围内,则认为它们相等并且此函数返回 false。
Name Type Description
left Number 要比较的第一个数字。
right Number 要比较的第二个数字。
absoluteEpsilon Number 用于比较的绝对 epsilon。
Returns:
如果 left 大于 right 大于 absoluteEpsilon . false if left is less or if the two values are nearly equal. ,则为 true 。 absoluteEpsilon . false if left is less or if the two values are nearly equal.

static Cesium.Math.greaterThanOrEquals (left, right, absoluteEpsilon) → Boolean

确定左值是否大于或等于右值。如果这两个值在彼此的 absoluteEpsilon 范围内,则认为它们相等并且此函数返回 true。
Name Type Description
left Number 要比较的第一个数字。
right Number 要比较的第二个数字。
absoluteEpsilon Number 用于比较的绝对 epsilon。
Returns:
如果 left 大于 right 或者值几乎相等,则为 true 。

static Cesium.Math.incrementWrap ( n , maximumValue , minimumValue ) → Number

如果数字超过最大值,则将带有换行的数字增加到最小值。
Name Type Default Description
n Number 可选 要增加的数字。
maximumValue Number 可选 滚动到最小值之前的最大增量值。
minimumValue Number 0.0 可选 超过最大值后重置为的数字。
Returns:
递增的数字。
Throws:
Example:
const n = Cesium.Math.incrementWrap(5, 10, 0); // returns 6
const m = Cesium.Math.incrementWrap(10, 10, 0); // returns 0

static Cesium.Math.isPowerOfTwo (n) → Boolean

确定非负整数是否为 2 的幂。由于 Javascript 中的 32 位按位运算符限制,允许的最大输入为 (2^32)-1。
Name Type Description
n Number 在 [0, (2^32)-1] 范围内测试的整数。
Returns:
如果数字是 2 的幂,则为 true ;否则, false 。
Throws:
Example:
const t = Cesium.Math.isPowerOfTwo(16); // true
const f = Cesium.Math.isPowerOfTwo(20); // false

static Cesium.Math.lerp (p, q, time) → Number

计算两个值的线性插值。
Name Type Description
p Number 要插值的起始值。
q Number 要插值的最终值。
time Number 插值时间一般在 [0.0, 1.0] 范围内。
Returns:
线性插值。
Example:
const n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0

static Cesium.Math.lessThan (left, right, absoluteEpsilon) → Boolean

确定左值是否小于右值。如果这两个值在彼此的 absoluteEpsilon 范围内,则认为它们相等并且此函数返回 false。
Name Type Description
left Number 要比较的第一个数字。
right Number 要比较的第二个数字。
absoluteEpsilon Number 用于比较的绝对 epsilon。
Returns:
如果 left 小于 right 大于 absoluteEpsilon . false if left is greater or if the two values are nearly equal. ,则为 true 。 absoluteEpsilon . false if left is greater or if the two values are nearly equal.

static Cesium.Math.lessThanOrEquals (left, right, absoluteEpsilon) → Boolean

确定左值是否小于或等于右值。如果这两个值在彼此的 absoluteEpsilon 范围内,则认为它们相等并且此函数返回 true。
Name Type Description
left Number 要比较的第一个数字。
right Number 要比较的第二个数字。
absoluteEpsilon Number 用于比较的绝对 epsilon。
Returns:
如果 left 小于 right 或者值几乎相等,则为 true 。

static Cesium.Math.log2 (number) → Number

求以 2 为底的对数。
Name Type Description
number Number 号码。
Returns:
结果。

static Cesium.Math.logBase (number, base) → Number

求一个数的底数的对数。
Name Type Description
number Number 号码。
base Number 基地。
Returns:
结果。

static Cesium.Math.mod (m, n) → Number

模运算也适用于负股息。
Name Type Description
m Number 红利。
n Number 除数。
Returns:
其余的。

static Cesium.Math.negativePiToPi (angle) → Number

在 -Pi <= angle <= Pi 范围内生成一个角度,它与提供的角度等价。
Name Type Description
angle Number 以弧度为单位
Returns:
[ -CesiumMath.PI , CesiumMath.PI ] 范围内的角度。

static Cesium.Math.nextPowerOfTwo (n) → Number

计算大于或等于提供的非负整数的下一个二次幂整数。由于 Javascript 中的 32 位按位运算符限制,允许的最大输入为 2^31。
Name Type Description
n Number 要在 [0, 2^31] 范围内测试的整数。
Returns:
下一个二的幂整数。
Throws:
Example:
const n = Cesium.Math.nextPowerOfTwo(29); // 32
const m = Cesium.Math.nextPowerOfTwo(32); // 32

static Cesium.Math.nextRandomNumber () → Number

使用 Mersenne twister 生成 [0.0, 1.0) 范围内的随机浮点数。
Returns:
[0.0, 1.0) 范围内的随机数。
See:

static Cesium.Math.normalize (value, rangeMinimum, rangeMaximum) → Number

将 [rangeMinimum, rangeMaximum] 范围内的标量值转换为 [0.0, 1.0] 范围内的标量
Name Type Description
value Number 范围内的标量值 [rangeMinimum, rangeMaximum]
rangeMinimum Number 映射范围内的最小值。
rangeMaximum Number 映射范围内的最大值。
Returns:
一个标量值,其中 rangeMinimum 映射到 0.0,rangeMaximum 映射到 1.0。

static Cesium.Math.previousPowerOfTwo (n) → Number

计算小于或等于提供的非负整数的前一个二次幂整数。由于 Javascript 中的 32 位按位运算符限制,允许的最大输入为 (2^32)-1。
Name Type Description
n Number 在 [0, (2^32)-1] 范围内测试的整数。
Returns:
前一个二的幂整数。
Throws:
Example:
const n = Cesium.Math.previousPowerOfTwo(29); // 16
const m = Cesium.Math.previousPowerOfTwo(32); // 32

static Cesium.Math.randomBetween (min, max) → Number

在两个数字之间生成一个随机数。
Name Type Description
min Number 最小值。
max Number 最大值。
Returns:
最小值和最大值之间的随机数。

static Cesium.Math.setRandomNumberSeed (seed)

在 CesiumMath#nextRandomNumber 中设置随机数生成器使用的种子。
Name Type Description
seed Number 用作种子的整数。

static Cesium.Math.sign (value) → Number

返回值的符号;如果值为正,则为 1,如果值为负,则为 -1,如果值为 0,则为 0。
Name Type Description
value Number 返回符号的值。
Returns:
价值的标志。

static Cesium.Math.signNotZero (value) → Number

如果给定值为正或零,则返回 1.0,如果为负,则返回 -1.0。这类似于 CesiumMath#sign ,除了当输入值为 0.0 时返回 1.0 而不是 0.0。
Name Type Description
value Number 返回符号的值。
Returns:
价值的标志。

static Cesium.Math.sinh (value) → Number

返回数字的双曲正弦值。 值 的双曲正弦定义为 ( e x - e -x )/2.0,其中 e 是欧拉数,大约为 2.71828183。

特别案例:

  • 如果参数为 NaN,则结果为 NaN。
  • 如果参数是无限的,则结果是与参数具有相同符号的无穷大。
  • 如果参数为零,则结果为零,其符号与参数相同。
Name Type Description
value Number 要返回其双曲正弦的数字。
Returns:
值的双曲正弦 value 。

static Cesium.Math.toDegrees (radians) → Number

将弧度转换为度数。
Name Type Description
radians Number 要转换为弧度的角度。
Returns:
以度为单位的相应角度。

static Cesium.Math.toRadians (degrees) → Number

将度数转换为弧度。
Name Type Description
degrees Number 以度为单位转换的角度。
Returns:
以弧度为单位的相应角度。

static Cesium.Math.toSNorm (value, rangeMaximum ) → Number

将 [-1.0, 1.0] 范围内的标量值转换为 [0, rangeMaximum] 范围内的 SNORM
Name Type Default Description
value Number [-1.0, 1.0] 范围内的标量值
rangeMaximum Number 255 可选 映射范围内的最大值,默认为 255。
Returns:
一个 SNORM 值,其中 0 映射到 -1.0,rangeMaximum 映射到 1.0。
See:
  • CesiumMath.fromSNorm

static Cesium.Math.zeroToTwoPi (angle) → Number

在 0 <= angle <= 2Pi 范围内生成一个角度,它与提供的角度等价。
Name Type Description
angle Number 以弧度为单位
Returns:
[0, CesiumMath.TWO_PI ] 范围内的角度。