Cesium and converted in a coordinate system

Before we start learning Entity, we first need to learn a coordinate system in the lower Cesium, Cesium there are multiple coordinate systems, often used to add during Entity.

First, the coordinate system is introduced

Let Cesium exemplified in the coordinate system: WGS84 latitude and longitude coordinates (no actual object), WGS84 coordinate system radians (Cartographic), Cartesian space Cartesian coordinate system (Cartesian3), plane coordinate system (Cartesian2), 4D Cartesian coordinate system (Cartesian4)

1, WGS84 coordinate system

World Geodetic System 1984, using the GPS global positioning system coordinate system established, the coordinates of the center of mass of Earth origin, its Z-axis Cartesian coordinate system of space geocentric point 1984.O definition of BIH (international time service) of the Earth's polar Agreement (CTP) direction, X-axis intersection point BIH 1984.0 zero meridian plane of the equator and CTP, Y and Z axes, X-axis perpendicular to the right-handed configuration. Compass on our usual phone displays is the current latitude and longitude coordinates of this coordinate system, the progress of the range [-180,180] latitude range [-90,90].
We all know that Cesium currently supports two coordinate systems WGS84 and WebMercator, but no actual object in Cesium to describe WGS84 coordinates are in radians way is to use the Cartographic categories: new Cesium.Cartographic (longitude, latitude , height), where the parameter is also called longitude, latitude, longitude and latitude is calculated method: rad = π / 180 × latitude and longitude angles.


 
WGS84 coordinate system

2, the spatial Cartesian rectangular coordinate system (Cartesian3)

Cartesian spatial coordinates of the origin is the center of the ellipsoid, when we draw on the computer, inconvenient to use latitude and longitude directly drawing, will generally coordinate system to a Cartesian coordinate system, using computer graphics knowledge for drawing. Cartesian3 here, somewhat similar in SuperMap iObejcts Point3D objects, new Cesium.Cartesian3 (x, y, z), which three components xyz.

 
Cartesian space Cartesian coordinate system

3, a plane coordinate system (Cartesian2)

Plane of plane coordinate system is a rectangular coordinate system is a two-dimensional Cartesian coordinate system, as compared with less Cartesian3 a z component of, new Cesium.Cartesian2 (x, y). Cartesian2 often used to describe the screen coordinate system, such as a mouse click on a position on the computer screen, is return Cartesian2, returned xy pixel position components of the mouse click.


 
Plane coordinate system

4,4D Cartesian coordinates (Cartesian4)

Up to now, it has not been used, such as a useful follow-up to time and then update it

Second, the use of several coordinate conversion method and system

Latitude and longitude and radians conversion

Coordinates radians: var = Cesium.CesiumMath.toRadians radians (degrees);
radians to Coordinates: var = Cesium.CesiumMath.toDegrees degrees (radians);
conversion methods Cesium source we look at, in fact: rad = π / 180 × angle of latitude and longitude; latitude angle = 180 / π × radians.

CesiumMath.RADIANS_PER_DEGREE = Math.PI / 180.0;
CesiumMath.DEGREES_PER_RADIAN = 180.0 / Math.PI;
CesiumMath.toRadians = function(degrees) { //>>includeStart('debug', pragmas.debug); if (!defined(degrees)) { throw new DeveloperError('degrees is required.'); } //>>includeEnd('debug'); return degrees * CesiumMath.RADIANS_PER_DEGREE; }; CesiumMath.toDegrees = function(radians) { //>>includeStart('debug', pragmas.debug); if (!defined(radians)) { throw new DeveloperError('radians is required.'); } //>>includeEnd('debug'); return radians * CesiumMath.DEGREES_PER_RADIAN; }; 

WGS84 latitude and longitude coordinates and convert radians WGS84 coordinates (of Cartographic) of

1.直接转换:通过上面提到的方法,将经纬度转换为弧度后,直接new Cesium.Cartographic(longitude弧度, latitude弧度, height米)
2.间接转换:通过var cartographic= Cesium.Cartographic.fromDegrees(longitude, latitude, height)直接转换;
类似的还有var cartographic= Cesium.Cartographic.fromRadians(longitude, latitude, height)方法,传入的是弧度。

WGS84坐标系和笛卡尔空间直角坐标系(Cartesian3)的转换

WGS84转为笛卡尔空间直角坐标系
1.通过经纬度或弧度进行转换:
var c3= Cesium.Cartesian3.fromDegrees(longitude, latitude, height) ;高度height可不填写。
var c3s=Cesium.Cartesian3.fromDegreesArray(coordinates);coordinates格式为不带高度的数组。例如:[-115.0, 37.0, -107.0, 33.0]
var c3s=Cesium.Cartesian3.fromDegreesArrayHeights(coordinates);coordinates格式为带有高度的数组。例如:[-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]
同理将度转化为弧度,然后再进行转换,
和上面一样有Cesium.Cartesian3.fromRadians,Cesium.Cartesian3.fromRadiansArray,Cesium.Cartesian3.fromRadiansArrayHeights等方法,用法和上面一样,只是度需要转换为弧度,这里不再讲这些方法。

其实fromDegrees内部也是用的fromRadians方法,这点大家可以了解下,另外WGS84坐标系转笛卡尔空间直角坐标系代码如下,大家可以了解下转换过程:

Cartesian3.fromRadians = function(longitude, latitude, height, ellipsoid, result) {
        //>>includeStart('debug', pragmas.debug);
        Check.typeOf.number('longitude', longitude); Check.typeOf.number('latitude', latitude); //>>includeEnd('debug'); height = defaultValue(height, 0.0); var radiiSquared = defined(ellipsoid) ? ellipsoid.radiiSquared : wgs84RadiiSquared; var cosLatitude = Math.cos(latitude); scratchN.x = cosLatitude * Math.cos(longitude); scratchN.y = cosLatitude * Math.sin(longitude); scratchN.z = Math.sin(latitude); scratchN = Cartesian3.normalize(scratchN, scratchN); Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK); var gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK)); scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK); scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN); if (!defined(result)) { result = new Cartesian3(); } return Cartesian3.add(scratchK, scratchN, result); }; 

2.通过度来进行转换
var position = Cesium.Cartographic.fromDegrees(longitude, latitude, height);
var c3 = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
var c3s=Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray([position1,position2,position3])
弧度同理
笛卡尔空间直角坐标系转换为WGS84
1.直接转换
var cartographic= Cesium.Cartographic.fromCartesian(cartesian3)
转换得到WGS84弧度坐标系后再使用经纬度和弧度的转换,进行转换到目标值
2、间接转换
var cartographic= Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian3)
var cartographics= Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray([cartesian1,cartesian2,cartesian3])

平面坐标系(Cartesian2)和笛卡尔空间直角坐标系(Cartesian3)的转换

平面坐标系转笛卡尔空间直角坐标系
这里需要说明的是当前的点必须在三维球上,否则返回的是undefined,我们在ScreenSpaceEventHandler回调会取到的坐标都是Cartesian2,大家可以测试观察下。
1.屏幕坐标转场景WGS84坐标,这里的场景坐标是包含了地形、倾斜、模型的坐标。
转换方法为:var cartesian3= viewer.scene.pickPosition(Cartesian2),目前IE浏览器不支持深度拾取,所以用不了这个方法。
2.屏幕坐标转地表坐标,这里是地球表面的WGS84坐标,包含地形,不包括模型、倾斜摄影表面。
转换方法为:var cartesian3= viewer.scene.globe.pick(viewer.camera.getPickRay(Cartesian2),viewer.scene);
3.屏幕坐标转椭球面坐标,这里的椭球面坐标是参考椭球的WGS84坐标,不包含地形、模型、倾斜摄影表面。
转换方法为:var cartesian3= viewer.scene.camera.pickEllipsoid(Cartesian2)
笛卡尔空间直角坐标系转平面坐标系
var cartesian2= Cesium.SceneTransforms.wgs84ToWindowCoordinates(viewer.scene,cartesian3)



作者:为梦齐舞
链接:https://www.jianshu.com/p/ed4bb38db9a4
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

Guess you like

Origin www.cnblogs.com/telwanggs/p/11289954.html