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

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

pi

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:
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, 如果 value 在范围 [-1.0, 1.0] 内,则为 value 的 acos;如果 value 超出该范围,则为 -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:
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, 如果 value 在范围 [-1.0, 1.0] 内,则为 value 的 asin;如果 value 超出该范围,则为 -1.0 或 1.0 的 asin 中较接近的那一个。

static Cesium.Math.cbrt(number)number

求一个数的立方根。 如果未提供 number,则返回 NaN。
Name Type Description
number number optional 数字。
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

返回一个数的双曲余弦。 value 的双曲余弦定义为 (ex + 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

使用绝对或相对容差测试判断两个值是否相等。这有助于 避免直接比较浮点值时因舍入误差导致的问题。首先使用绝对容差测试进行比较; 如果未通过,则执行相对容差测试。 如果你不确定 left 和 right 的数量级,请使用此测试。
Name Type Default Description
left number 要比较的第一个值。
right number 要比较的另一个值。
relativeEpsilon number 0 optional 用于相对容差测试的 leftright 之间的最大包含性差值。
absoluteEpsilon number relativeEpsilon optional 用于绝对容差测试的 leftright 之间的最大包含性差值。
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 License 改编自 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 optional SNORM 范围内的最大值,默认为 255。
Returns:
范围 [-1.0, 1.0] 内的标量。
See:
  • CesiumMath.toSNorm

static Cesium.Math.greaterThan(left, right, absoluteEpsilon)boolean

判断 left 值是否大于 right 值。如果两个值在 absoluteEpsilon 范围内,则视为相等,此函数返回 false。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
true if left is greater than right by more than absoluteEpsilon,则为 true;如果 left 更小或两者 几乎相等,则为 false

static Cesium.Math.greaterThanOrEquals(left, right, absoluteEpsilon)boolean

判断 left 值是否大于或等于 right 值。如果两个值在 absoluteEpsilon 范围内,则视为相等,此函数返回 true。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
true if left is greater than right or if the 两者几乎相等,则为 true

static Cesium.Math.incrementWrap(n, maximumValue, minimumValue)number

递增一个数字,如果超过最大值则回绕到最小值。
Name Type Default Description
n number optional 要递增的数字。
maximumValue number optional 回绕到最小值之前的最大递增值。
minimumValue number 0.0 optional 超过最大值后重置到的数字。
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

判断 left 值是否小于 right 值。如果两个值在 absoluteEpsilon 范围内,则视为相等,此函数返回 false。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
true if left is less than right by more than absoluteEpsilon,则为 true;如果 left 更大或两者 几乎相等,则为 false

static Cesium.Math.lessThanOrEquals(left, right, absoluteEpsilon)boolean

判断 left 值是否小于或等于 right 值。如果两个值在 absoluteEpsilon 范围内,则视为相等,此函数返回 true。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
true if left is less than right or if the 两者几乎相等,则为 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

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

static Cesium.Math.nextRandomNumber()number

使用梅森旋转算法生成范围 [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

计算小于或等于所提供非负整数的前一个 2 的幂整数。 由于 Javascript 中 32 位位运算符的限制,允许的最大输入为 (2^32)-1。
Name Type Description
n number 要测试的整数,范围 [0, (2^32)-1]。
Returns:
前一个 2 的幂整数。
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:
value 的符号。

static Cesium.Math.signNotZero(value)number

如果给定值为正或零,则返回 1.0;如果为负,则返回 -1.0。 这与 CesiumMath#sign 类似,区别在于当输入值为 0.0 时返回 1.0 而非 0.0。
Name Type Description
value number 要返回其符号的值。
Returns:
value 的符号。

static Cesium.Math.sinh(value)number

返回一个数的双曲正弦。 value 的双曲正弦定义为 (ex - 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 The angle to convert 以弧度为单位.
Returns:
对应的角度,以度为单位。

static Cesium.Math.toRadians(degrees)number

将度转换为弧度。
Name Type Description
degrees number 要转换的角度,以度为单位。
Returns:
The corresponding angle 以弧度为单位.

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 optional 映射范围内的最大值,默认为 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] 内的角。
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。