麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

Cesium API - Math 中文文档

本文介绍下Cesium中 Math API的详细使用说明。

Math API 调用方法

数学函数。

成员变量

staticconstantCesium.Math.DEGREES_PER_RADIAN : Number
The number of degrees in a radian.
Default Value: 180.0 / Math.PI
staticconstantCesium.Math.EPSILON1 : Number
0.1
staticconstantCesium.Math.EPSILON2 : Number
0.01
staticconstantCesium.Math.EPSILON3 : Number
0.001
staticconstantCesium.Math.EPSILON4 : Number
0.0001
staticconstantCesium.Math.EPSILON5 : Number
0.00001
staticconstantCesium.Math.EPSILON6 : Number
0.000001
staticconstantCesium.Math.EPSILON7 : Number
0.0000001
staticconstantCesium.Math.EPSILON8 : Number
0.00000001
staticconstantCesium.Math.EPSILON9 : Number
0.000000001
staticconstantCesium.Math.EPSILON10 : Number
0.0000000001
staticconstantCesium.Math.EPSILON11 : Number
0.00000000001
staticconstantCesium.Math.EPSILON12 : Number
0.000000000001
staticconstantCesium.Math.EPSILON13 : Number
0.0000000000001
staticconstantCesium.Math.EPSILON14 : Number
0.00000000000001
staticconstantCesium.Math.EPSILON15 : Number
0.000000000000001
staticconstantCesium.Math.EPSILON16 : Number
0.0000000000000001
staticconstantCesium.Math.EPSILON17 : Number
0.00000000000000001
staticconstantCesium.Math.EPSILON18 : Number
0.000000000000000001
staticconstantCesium.Math.EPSILON19 : Number
0.0000000000000000001
staticconstantCesium.Math.EPSILON20 : Number
0.00000000000000000001
staticconstantCesium.Math.EPSILON21 : Number
0.000000000000000000001
staticconstantCesium.Math.FOUR_GIGABYTES : Number
4 * 1024 * 1024 * 1024
staticconstantCesium.Math.GRAVITATIONALPARAMETER : Number
The gravitational parameter of the Earth in meters cubed per second squared as defined by the WGS84 model: 3.986004418e14
staticconstantCesium.Math.LUNAR_RADIUS : Number
The mean radius of the moon, according to the "Report of the IAU/IAG Working Group on Cartographic Coordinates and Rotational Elements of the Planets and satellites: 2000", Celestial Mechanics 82: 83-110, 2002.
staticconstantCesium.Math.ONE_OVER_PI : Number
1/pi
staticconstantCesium.Math.ONE_OVER_TWO_PI : Number
1/2pi
staticconstantCesium.Math.PI : Number
pi
staticconstantCesium.Math.PI_OVER_FOUR : Number
pi/4
staticconstantCesium.Math.PI_OVER_SIX : Number
pi/6
staticconstantCesium.Math.PI_OVER_THREE : Number
pi/3
staticconstantCesium.Math.PI_OVER_TWO : Number
pi/2
staticconstantCesium.Math.RADIANS_PER_ARCSECOND : Number
The number of radians in an arc second.
Default Value: CesiumMath.RADIANS_PER_DEGREE / 3600.0
staticconstantCesium.Math.RADIANS_PER_DEGREE : Number
The number of radians in a degree.
Default Value: Math.PI / 180.0
staticconstantCesium.Math.SIXTY_FOUR_KILOBYTES : Number
64 * 1024
staticconstantCesium.Math.SOLAR_RADIUS : Number
以米为单位的太阳半径: 6.955e8
staticconstantCesium.Math.THREE_PI_OVER_TWO : Number
3pi/2
staticconstantCesium.Math.TWO_PI : Number
2pi

内置方法

staticCesium.Math.acosClamped(value)Number
Computes Math.acos(value), but first clamps value to the range [-1.0, 1.0] so that the function will never return NaN.
Name Type Description
value Number The value for which to compute acos.
返回值:
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, whichever is closer, if the value is outside the range.
staticCesium.Math.asinClamped(value)Number
Computes Math.asin(value), but first clamps value to the range [-1.0, 1.0] so that the function will never return NaN.
Name Type Description
value Number The value for which to compute asin.
返回值:
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, whichever is closer, if the value is outside the range.
staticCesium.Math.cbrt(number)Number
Finds the cube root of a number. Returns NaN if number is not provided.
Name Type Description
number Number optional The number.
返回值:
The result.
staticCesium.Math.chordLength(angle, radius)Number
Finds the chord length between two points given the circle's radius and the angle between the points.
Name Type Description
angle Number The angle between the two points.
radius Number The radius of the circle.
返回值:
The chord length.
staticCesium.Math.clamp(value, min, max)Number
将一个值限制在两个值之间。
Name Type Description
value Number 要限制的值。
min Number 最小值。
max Number 最大值。
返回值:
value被夹住,使得min <= value <= max。
staticCesium.Math.clampToLatitudeRange(angle)Number
Convenience function that clamps a latitude value, in radians, to the range [-Math.PI/2, Math.PI/2). Useful for sanitizing data before use in objects requiring correct range.
Name Type Description
angle Number The latitude value, in radians, to clamp to the range [-Math.PI/2, Math.PI/2).
返回值:
The latitude value clamped to the range [-Math.PI/2, Math.PI/2).
示例:
// Clamp 108 degrees latitude to 90 degrees latitude
var latitude = Cesium.Math.clampToLatitudeRange(Cesium.Math.toRadians(108.0));
staticCesium.Math.convertLongitudeRange(angle)Number
Converts a longitude value, in radians, to the range [-Math.PI, Math.PI).
Name Type Description
angle Number The longitude value, in radians, to convert to the range [-Math.PI, Math.PI).
返回值:
The equivalent longitude value in the range [-Math.PI, Math.PI).
示例:
// Convert 270 degrees to -90 degrees longitude
var longitude = Cesium.Math.convertLongitudeRange(Cesium.Math.toRadians(270.0));
staticCesium.Math.cosh(value)Number
Returns the hyperbolic cosine of a number. The hyperbolic cosine of value is defined to be (ex + e-x)/2.0 where e is Euler's number, approximately 2.71828183.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is positive infinity.
  • If the argument is zero, then the result is 1.0.

Name Type Description
value Number The number whose hyperbolic cosine is to be returned.
返回值:
The hyperbolic cosine of value.
staticCesium.Math.equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon)Boolean
使用绝对或相对容差测试确定两个值是否相等。在直接比较浮点值时,这有助于避免由于舍入错误造成的问题。这些值首先使用绝对容差测试进行比较。 如果失败,则执行相对容错测试。如果你不确定左右的大小,可以使用这个测试。
Name Type Default Description
left Number 要比较的第一个值。
right Number 要比较的另一个值。
relativeEpsilon Number 相对容差测试用的leftright
absoluteEpsilon Number relativeEpsilon optional 绝对容差测试用的leftright
返回值:
true,如果值在epsilon内相等;否则,false
示例:
var a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
var b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2);  // false
var c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true
var d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false
staticCesium.Math.factorial(n)Number
计算所提供数字的阶乘。
Name Type Description
n Number 要计算其阶乘的数。
返回值:
给定数的阶乘,如果该数小于0,则未定义。
异常情况:
示例:
//Compute 7!, which is equal to 5040
var computedFactorial = Cesium.Math.factorial(7);
参考:
staticCesium.Math.fastApproximateAtan(x)Number
Computes a fast approximation of Atan for input in the range [-1, 1]. Based on Michal Drobot's approximation from ShaderFastLibs, which in turn is based on "Efficient approximations for the arctangent function," Rajan, S. Sichun Wang Inkol, R. Joyal, A., May 2006. Adapted from ShaderFastLibs under MIT License.
Name Type Description
x Number An input number in the range [-1, 1]
返回值:
An approximation of atan(x)
staticCesium.Math.fastApproximateAtan2(x, y)Number
Computes a fast approximation of Atan2(x, y) for arbitrary input scalars. Range reduction math based on nvidia's cg reference implementation: http://developer.download.nvidia.com/cg/atan2.html
Name Type Description
x Number An input number that isn't zero if y is zero.
y Number An input number that isn't zero if x is zero.
返回值:
An approximation of atan2(x, y)
staticCesium.Math.fromSNorm(value, rangeMaximum)Number
Converts a SNORM value in the range [0, rangeMaximum] to a scalar in the range [-1.0, 1.0].
Name Type Default Description
value Number SNORM value in the range [0, rangeMaximum]
rangeMaximum Number 255 optional The maximum value in the SNORM range, 255 by default.
返回值:
Scalar in the range [-1.0, 1.0].
参考:
  • CesiumMath.toSNorm
staticCesium.Math.greaterThan(left, right, absoluteEpsilon)Boolean
确定左值是否大于右值。如果这两个值在absoluteEpsilon内,则认为它们相等,此函数返回false。
Name Type Description
left Number 第一个要比较的数字。
right Number 第二个要比较的数字。
absoluteEpsilon Number 用于比较的绝对值。
返回值:
true如果left大于right超过absoluteEpsilonfalse如果left小于或如果两个值接近相等。
staticCesium.Math.greaterThanOrEquals(left, right, absoluteEpsilon)Boolean
确定左值是否大于或等于右值。如果这两个值在absoluteEpsilon内,则认为它们相等,此函数返回true。
Name Type Description
left Number 第一个要比较的数字。
right Number 第二个要比较的数字。
absoluteEpsilon Number 用于比较的绝对值。
返回值:
true如果left大于right或者如果值接近相等。
staticCesium.Math.incrementWrap(n, maximumValue, minimumValue)Number
Increments a number with a wrapping to a minimum value if the number exceeds the maximum value. 如果一个数字超过了最大值,则使用包装将其递增到最小值。
Name Type Default Description
n Number optional 要增加的数。
maximumValue Number optional 在转到最小值之前增加的最大值。
minimumValue Number 0.0 optional 超过最大值后重置的数字。
返回值:
增加的数。
异常情况:
示例:
var n = Cesium.Math.incrementWrap(5, 10, 0); // returns 6
var n = Cesium.Math.incrementWrap(10, 10, 0); // returns 0
staticCesium.Math.isPowerOfTwo(n)Boolean
确定一个正整数是否是2的幂。
Name Type Description
n Number 要测试的正整数。
返回值:
true如果数是2的幂;否则,false
异常情况:
示例:
var t = Cesium.Math.isPowerOfTwo(16); // true
var f = Cesium.Math.isPowerOfTwo(20); // false
staticCesium.Math.lerp(p, q, time)Number
Computes the linear interpolation of two values.
Name Type Description
p Number The start value to interpolate.
q Number The end value to interpolate.
time Number The time of interpolation generally in the range [0.0, 1.0].
返回值:
The linearly interpolated value.
示例:
var n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0
staticCesium.Math.lessThan(left, right, absoluteEpsilon)Boolean
确定左值是否小于右值。如果这两个值在absoluteEpsilon内,则认为它们相等,此函数返回false。
Name Type Description
left Number 第一个要比较的数字。
right Number 第二个要比较的数字。
absoluteEpsilon Number 用于比较的绝对值。
返回值:
true如果left小于right超过absoluteEpsilonfalse如果left大于或如果两个值接近相等。
staticCesium.Math.lessThanOrEquals(left, right, absoluteEpsilon)Boolean
确定左值是否小于或等于右值。如果这两个值在absoluteEpsilon内,则认为它们相等,此函数返回true。
Name Type Description
left Number 第一个要比较的数字。
right Number 第二个要比较的数字。
absoluteEpsilon Number 用于比较的绝对值。
返回值:
true如果left小于right或者如果值接近相等。
staticCesium.Math.log2(number)Number
Finds the base 2 logarithm of a number.
Name Type Description
number Number The number.
返回值:
The result.
staticCesium.Math.logBase(number, base)Number
Finds the logarithm of a number to a base.
Name Type Description
number Number The number.
base Number The base.
返回值:
The result.
staticCesium.Math.mod(m, n)Number
The modulo operation that also works for negative dividends.
Name Type Description
m Number The dividend.
n Number The divisor.
返回值:
The remainder.
staticCesium.Math.negativePiToPi(angle)Number
Produces an angle in the range -Pi <= angle <= Pi which is equivalent to the provided angle.
Name Type Description
angle Number in radians
返回值:
The angle in the range [-CesiumMath.PI, CesiumMath.PI].
staticCesium.Math.nextPowerOfTwo(n)Number
计算下一个大于或等于给定正整数的2次幂。
Name Type Description
n Number 要测试的正整数。
返回值:
下一个2的幂数。
异常情况:
示例:
var n = Cesium.Math.nextPowerOfTwo(29); // 32
var m = Cesium.Math.nextPowerOfTwo(32); // 32
staticCesium.Math.nextRandomNumber()Number
使用梅森扭距(Mersenne twister)生成一个范围为[0.0,1.0)的随机浮点数。
返回值:
一个在[0.0,1.0)范围内的随机数。
参考:
staticCesium.Math.normalize(value, rangeMinimum, rangeMaximum)Number
Converts a scalar value in the range [rangeMinimum, rangeMaximum] to a scalar in the range [0.0, 1.0]
Name Type Description
value Number The scalar value in the range [rangeMinimum, rangeMaximum]
rangeMinimum Number The minimum value in the mapped range.
rangeMaximum Number The maximum value in the mapped range.
返回值:
A scalar value, where rangeMinimum maps to 0.0 and rangeMaximum maps to 1.0.
staticCesium.Math.randomBetween(min, max)Number
在两个数字之间生成一个随机数。
Name Type Description
min Number 最小值。
max Number 最大值。
返回值:
最小值和最大值之间的一个随机数。
staticCesium.Math.setRandomNumberSeed(seed)
CesiumMath#nextRandomNumber中设置随机数生成器使用的种子。
Name Type Description
seed Number 用作种子的整数。
staticCesium.Math.sign(value)Number
Returns the sign of the value; 1 if the value is positive, -1 if the value is negative, or 0 if the value is 0.
Name Type Description
value Number The value to return the sign of.
返回值:
The sign of value.
staticCesium.Math.signNotZero(value)Number
Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. This is similar to CesiumMath#sign except that returns 1.0 instead of 0.0 when the input value is 0.0.
Name Type Description
value Number The value to return the sign of.
返回值:
The sign of value.
staticCesium.Math.sinh(value)Number
Returns the hyperbolic sine of a number. The hyperbolic sine of value is defined to be (ex - e-x)/2.0 where e is Euler's number, approximately 2.71828183.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is an infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Name Type Description
value Number The number whose hyperbolic sine is to be returned.
返回值:
The hyperbolic sine of value.
staticCesium.Math.toDegrees(radians)Number
Converts radians to degrees.
Name Type Description
radians Number The angle to convert in radians.
返回值:
The corresponding angle in degrees.
staticCesium.Math.toRadians(degrees)Number
Converts degrees to radians.
Name Type Description
degrees Number The angle to convert in degrees.
返回值:
The corresponding angle in radians.
staticCesium.Math.toSNorm(value, rangeMaximum)Number
Converts a scalar value in the range [-1.0, 1.0] to a SNORM in the range [0, rangeMaximum]
Name Type Default Description
value Number The scalar value in the range [-1.0, 1.0]
rangeMaximum Number 255 optional The maximum value in the mapped range, 255 by default.
返回值:
A SNORM value, where 0 maps to -1.0 and rangeMaximum maps to 1.0.
参考:
  • CesiumMath.fromSNorm
staticCesium.Math.zeroToTwoPi(angle)Number
在0 <=角度<= 2PI范围内产生一个角度,该角度与提供的角度相等。
Name Type Description
angle Number 以弧度表示
返回值:
角度在[0, CesiumMath.TWO_PI ]范围内。

其他API

Cesium中文API文档手册(v1.63.1版本)参考:《Cesium中文API文档手册(v1.63.1版本)

相关阅读

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
公众号关注
知识星球
手机阅读
麻辣GIS微信公众号关注
最新GIS干货
关注麻辣GIS知识星球
私享圈子

留言板(小编看到第一时间回复)