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", 天体力学 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:
如果值在范围 [-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 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 要钳制的纬度值,单位为弧度。
Returns:
钳制后的纬度值,范围在 [-Math.PI/2, Math.PI/2) 内。
Example:
// 将 108 度纬度钳制到 90 度纬度
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 要转换的经度值,单位为弧度。
Returns:
等效的经度值,范围在 [-Math.PI, Math.PI) 内。
Example:
// 将 270 度转换为 -90 度经度
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

使用绝对或相对容差测试确定两个值是否相等。这对于 避免直接比较浮点值时因舍入误差引起的问题很有用。首先 使用绝对容差测试比较值。如果失败,则执行相对容差测试。 如果不确定左右值的大小,请使用此测试。
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:
//计算 7!,等于 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 optional 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,则返回 true。如果 left 较小或两个 值几乎相等,则返回 false

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 optional 要递增的数字。
maximumValue number optional 回绕到最小值之前的最大递增值。
minimumValue number 0.0 optional 超过最大值后重置到的数字。
Returns:
递增后的数字。
Throws:
Example:
const n = Cesium.Math.incrementWrap(5, 10, 0); // 返回 6
const m = Cesium.Math.incrementWrap(10, 10, 0); // 返回 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); // 返回 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,则返回 true。如果 left 较大或两个 值几乎相等,则返回 false

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

计算大于或等于所提供非负整数的下一个 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

使用 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

计算小于或等于所提供非负整数的上一个 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:
min 和 max 之间的随机数。

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 要转换的角度,单位为弧度。
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 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] 内的角度。
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.