cesium learning (f) coordinate conversion

cesium learning ( six ) coordinate conversion

I. Introduction

  In the scene, whether it is two-dimensional or three-dimensional Fortunately worth mentioning, as long as it comes to the concept of space will be referred to coordinate, let us understand the position coordinates of a very effective thing. With the coordinates, we can quickly determine the location of the correlation, but there are many coordinates, the professional said, there are many coordinate systems, such as earth 2000 , Beijing 54 and Xi'an 80 , WGS84 , Mercator coordinate system ...... there are various parts of the local coordinate system. If Beijing 54 coordinates into the WGS84 coordinates to use, you will find the galaxy bias is not that it makes you wonder life!

  So we need this thing coordinate transformation to convert the coordinates into a coordinate system of the coordinate system of the other wanted.

Two, the GPS coordinates of the turn Cartesian3 coordinates

  Cesium provides a method for converting the two coordinate systems is relatively simple, can be directly converted, but one thing is Cartesian3 convert coordinates to GPS time coordinates, it is the result of radians, not the angle value, so if we need common GPS coordinates will need to convert it to convert radians angle.

// GPS turn world coordinates ( the X-, the y-, z )

this.GPSToWorldCoordinate = function(longtitude,latitude,height){

    var result = Cesium.Cartesian3.fromDegrees(longtitude, latitude, height);

    return result;

};

// world coordinates turn GPS coordinates (angle values) [ longitude, latitude, altitude ]

this.WorldCoordinateToGPS = function(x,y,z){

    var result = Cesium.Cartographic.fromCartesian(new Cesium.Cartesian3(x,y,z));

    var arr = [result.longitude*180/Math.PI,result.latitude*180/Math.PI,result.height];

    return arr;

};

三、Transforms

  Cesium is Transforms doing really good, just the beginning of all my coordinate transformations in particular the World coordinates Matrix4 conversion, simply do not understand, okay API speak very clearly, can not do otherwise is simply a series of coordinates calculation.

  For coordinate conversion, it is recommended to see Cesium is Transforms class. There are a lot associated with the coordinate transformation methods (including screen coordinates and world coordinates of each conversion), such as the following I made a relative coordinate and the world coordinate conversion on the use of Transfroms way.

Fourth, the local coordinates of the world coordinate

  Made himself a world class local coordinate conversion, the establishment of a local coordinates, then calculates each other.

 /**

 * Relative coordinate system and the world coordinate system conversion, the relative coordinate system axis direction by the optional parameter direction control, default eastNorthUp north, east, on the axis

 *

 * @Param {Number} longitude Lon world coordinate system

 * @Param {Number} latitude Lat world coordinate system

 * @Param height {Number} height of the world coordinate system

 * @Param {Number} direction coordinate axis, the value is "northEastDown", "northUpEast", "northWestUp", "eastNorthUp" ( default )

 */

var LocalAndWorldTransform = function(longitude,latitude,height,direction){

 

    var RCSorigincenter = Cesium.Cartesian3.fromDegrees(longitude,latitude,height);

    if (direction == "northEastDown")

        this.RCSMatrix = Cesium.Transforms.northEastDownToFixedFrame(RCSorigincenter);

    else if (direction == "northUpEast")

        this.RCSMatrix = Cesium.Transforms.northUpEastToFixedFrame(RCSorigincenter);

    else if (direction == "northWestUp")

        this.RCSMatrix = Cesium.Transforms.northWestUpToFixedFrame(RCSorigincenter);

    else

        this.RCSMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(RCSorigincenter);

    this.RCSmatrixInverse = Cesium.Matrix4.inverseTransformation(this.RCSMatrix, new Cesium.Matrix4());

 

  /**

   * 相对坐标转换成对应的世界坐标

   *

   * @param {Object} localCoordinates 相对坐标系中的坐标,如 {x:1,y:1,z:1}

   * @param {Object} result 世界坐标系中的对应坐标,XYZ格式

   * @returns

   */

  this.localToWorldCoordinates = function(localCoordinates, result){

      if (!result) {

          result = new Cesium.Cartesian3();

      }

      Cesium.Matrix4.multiplyByPoint(this.RCSMatrix, localCoordinates, result);

      return result;

  };

 

  /**

   * 世界坐标转换成对应的相对坐标

   *

   * @param {Object} WorldCoordinates 世界坐标系中的坐标,XYZ格式

   * @param {Object} result 相对坐标系中的坐标,XYZ格式

   * @returns

   */

  this.WorldCoordinatesTolocal = function(WorldCoordinates, result){

      if (!result) {

          result = new Cesium.Cartesian3();

      }

      Cesium.Matrix4.multiplyByPoint(this.RCSmatrixInverse, WorldCoordinates, result);

      return result;

  };

};

 

五、总结

  总的来说,Cesium对于坐标转换已经给我们做的太好了,大多时候我们直接使用即可。因为我有很多地方都用到了相对坐标与世界坐标的转换,所以自己就做了一个公共方法。在使用中还是很方便的,实例化一个相对转换关系对象,然后就可以互转了(: P)。

 

Guess you like

Origin www.cnblogs.com/CreateFree/p/11244512.html