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 要限制在范围 [-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

使用绝对或相对公差测试确定两个值是否相等。这对于避免由于四舍五入误差直接比较浮点值时出现的问题非常有用。 首先使用绝对公差测试进行比较。如果该测试失败,则进行相对公差测试。 如果不确定左右值的大小,请使用此测试。
Name Type Default Description
left number 第一个要比较的值。
right number 另一个要比较的值。
relativeEpsilon number 0 optional 对于相对公差测试,leftright 之间的最大包含差值。
absoluteEpsilon number relativeEpsilon optional 对于绝对公差测试,leftright 之间的最大包含差值。
Returns:
如果在公差范围内值相等,则返回 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 中的近似, 该近似又基于 "Efficiency approximations for the arctangent function," Rajan, S. Sichun Wang Inkol, R. Joyal, A.,2006年5月。 从 ShaderFastLibs 根据 MIT 许可进行调整。
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 在比较中使用的绝对公差。
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 在比较中使用的绝对公差。
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); // returns 6
const m = Cesium.Math.incrementWrap(10, 10, 0); // returns 0

static Cesium.Math.isPowerOfTwo(n)boolean

确定一个非负整数是否是二的幂。 由于 JavaScript 中 32 位位运算符的限制,最大允许输入为 (2^32)-1。
Name Type Description
n number 要测试的整数,范围在 [0, (2^32)-1] 内。
Returns:
如果数字是二的幂,则返回 true;否则返回 false
Throws:
  • DeveloperError : 需要一个介于 0 和 (2^32)-1 之间的数字。
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 在比较中使用的绝对公差。
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 在比较中使用的绝对公差。
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

生成一个范围在 [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:
  • DeveloperError : 需要一个介于 0 和 (2^32)-1 之间的数字。
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:
值的符号。

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

返回一个数的双曲正弦。 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] 的角度。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.