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

圆周率

static constant Cesium.Math.PI_OVER_FOUR : number

圆周率/4

static constant Cesium.Math.PI_OVER_SIX : number

圆周率/6

static constant Cesium.Math.PI_OVER_THREE : number

圆周率/3

static constant Cesium.Math.PI_OVER_TWO : number

圆周率/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),但首先将限制在 [-1.0, 1.0] 范围内 的请求,以便函数永远不会返回 NaN。
Name Type Description
value number 要计算 acos 的值。
Returns:
值的 acos(如果值在 [-1.0, 1.0] 范围内,或者 acos 为 -1.0 或 1.0, 如果值超出范围,则以较接近者为准。

static Cesium.Math.asinClamped(value)number

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

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

Constraint a value to lie between two values.
Name Type Description
value number 夹位的值。
min number The minimum value.
max number The maximum value.
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:
// 将 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

使用绝对或相对容差测试确定两个值是否相等。这很有用 以避免在直接比较浮点值时由于舍入错误而引起的问题。这些值为 首先使用绝对公差测试进行比较。如果失败,则执行相对容忍度测试。 如果您不确定 left 和 right 的大小,请使用此测试。
Name Type Default Description
left number 要比较的第一个值。
right number 要比较的另一个值。
relativeEpsilon number 0 optional 相对容差测试的左右之间的最大包含增量。
absoluteEpsilon number relativeEpsilon optional 绝对容差测试的左右之间的最大包含增量。
Returns:
true,如果 epsilon 内的值相等;否则为 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!,等于 5040
const computedFactorial = Cesium.Math.factorial(7);
See:

static Cesium.Math.fastApproximateAtan(x)number

计算 [-1, 1] 范围内输入的 Atan 的快速近似值。 基于 Michal Drobot 在 ShaderFastLibs 中的近似值, 反过来又基于“反正切函数的有效近似”, 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(值, rangeMaximum)number

将 [0, rangeMaximum] 范围内的 SNORM 值转换为 [-1.0, 1.0] 范围内的标量。
Name Type Default Description
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 的 epsilon 中,则它们被认为是相等的,并且此函数返回 false。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
true,如果 left 大于 right 大于 绝对的 Epsilon.如果 left 小于 left,或者如果两个 值几乎相等。

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

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

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:
true,如果数字是 2 的幂;否则为 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 的 epsilon 中,则它们被认为是相等的,并且此函数返回 false。
Name Type Description
left number 要比较的第一个数字。
right number 要比较的第二个数字。
absoluteEpsilon number 用于比较的绝对 epsilon。
Returns:
如果left 小于 right 大于 则true Absolute Epsilon如果 left 大于 left,或者如果 2 值几乎相等。

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

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

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] 范围内的随机浮点数 使用 Mersenne twister。
Returns:
一个 [0.0, 1.0] 范围内的随机数。
See:

static Cesium.Math.normalize(值, rangeMinimum, rangeMaximum)number

将 [rangeMinimum, rangeMaximum] 范围内的标量值转换为 [0.0, 1.0] 范围内的标量
Name Type Description
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:
值的符号。

static Cesium.Math.signNotZero(value)number

如果给定值为正数或零,则返回 1.0,如果给定值为负数,则返回 -1.0。 这类似于 CesiumMath#sign,只是返回 1.0 而不是 输入值为 0.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(值, rangeMaximum)number

将 [-1.0, 1.0] 范围内的标量值转换为 [0, rangeMaximum] 范围内的 SNORM
Name Type Default Description
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 <= 角度 <= 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.