CESIUMJS Development Practice (v) Coordinate transformation __js

Source: Internet
Author: User
Absrtact: There are two WGS84 geographical coordinate systems and Cartesian space coordinate system for the coordinates commonly used in cesium.

The coordinates commonly used in cesium have two kinds of WGS84 geographical coordinate system and Cartesian space coordinate system. We usually use the latitude and longitude to specify a location is used in the WGS84 coordinates, the Cartesian space coordinate system is often used to do some space transformation such as translation and rotation scaling. The relationship between the two is shown below

The origin of Cartesian space coordinates is the center of the ellipsoid.

The most operations used in practical applications are the conversion between (LNG, LAT, alt) <=> (x, Y, z), and CESIUMJS provides us with these transformations

var ellipsoid = viewer.scene.globe.ellipsoid;
var coord_wgs84 = Cesium.Cartographic.fromDegrees (LNG, lat, alt);/unit: degrees, degrees, meters
var coord_xyz = Ellipsoid.cartographictocartesian (COORD_WGS84);
Console.log (' x= ' + coord_xyz.x + ', y= ' + coord_xyz.y + ', z= ' + coord_xyz.z);/unit: M, M, M

var xyz = new Cesium.cartesian3 (x, y, z);
var WGS84 = ellipsoid.cartesiantocartographic (xyz);
Console.log (' lng= ' + Cesium.Math.toDegrees (wgs84.longitude) + ', lat= ' + Cesium.Math.toDegrees (wgs84.latitude) + ', alt= ' + wgs84.height);


Note that the angle units within the cesium are radians, so you need to convert the input calculation or output display.

The transformation to Cartesian coordinate system can use the affine transformation knowledge in computer graphics to carry out spatial position transformation such as translation rotation scaling. CESIUMJS provides us with a very useful transformation tool class, CESIUM.CARTESIAN3 (equivalent to Point3D) cesium.matrix3 (3x3 matrix, used to describe rotational transformations) cesium.matrix4 (4x4 matrix, used to describe the rotation plus translation transformation), cesium.quaternion (four yuan number, used to describe the surrounding A transformation in which a vector rotates at a certain angle. Here's an example:

A point whose local coordinates are P1 (x,y,z) places its local coordinate origin on the LOC (Lng,lat,alt), the z axis of the local coordinates is perpendicular to the surface, and the y-axis of the local coordinates is to the north, and rotates the D degree around the z axis, for this time P1 (x,y,z) Transform to global coordinates Cartesian sit P2 (x1,y1,z1) is how much.

Var rotate = cesium.math.toradians (d);/turn into radians var quat =  Cesium.Quaternion.fromAxisAngle (cesium.cartesian3.unit_z, rotate);  //quat is a four-dollar number that rotates d degrees around this Z-axis Var rot _mat3 = cesium.matrix3.fromquaternion (Quat);//ROT_MAT3 is a rotational matrix based on a four-dollar number var v = new  CESIUM.CARTESIAN3 (x, y, z);//p1 Local coordinates var m = cesium.matrix4.fromrotationtranslation ( Rot_mat3, cesium.cartesian3.zero); M2 is the 4x4 transformation matrix for the rotation kapyong shift, which translates to (0,0,0), so fill in a Cesium.Cartesian3.ZERO m =  Cesium.Matrix4.multiplyByTranslation (m, v);//m = m x v var cart3 =  Ellipsoid.cartographictocartesian (Cesium.Cartographic.fromDegrees (Lng, lat, alt));  // The global coordinate var m1 = cesium.transforms.eastnorthuptofixedframe (CART3) of the local coordinate origin is obtained, and the z axis of the local coordinate is//m1 perpendicular to the surface, The y-axis of the local coordinates points to the 4x4 transformation matrix m = cesium.matrix4.multiplytransformation (M,&NBSP;M1);//m = m x &NBSP;M1 Var p2 = cesium.matrix4.gettranSlation (m)//According to the final transformation matrix M gets P2 console.log (' x= '  + p2.x +  ', y= '  + p2.y +  ', Z = '  + p2.z ];

This concludes the next article "Cesiumjs Development Practice (vi) CZML"

Original: https://my.oschina.net/u/1585572/blog/290548

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.