首页 > 建站教程 > 地图,GIS教程 >  Cesium Cartesian3笛卡尔坐标系详解和转换正文

Cesium Cartesian3笛卡尔坐标系详解和转换

Cartesian的翻译为"笛卡尔",实际上Cartesian3是来储存点的X/Y/Z坐标的,其中的方法也是服务于这一点,请大家记住这一点。以下就简称之为C3。

一、经纬度转换为世界坐标
1.Cesium.Cartesian3.fromDegrees(longitude, latitude, height, ellipsoid, result)

2.var ellipsoid=viewer.scene.globe.ellipsoid;
  var cartographic=Cesium.Cartographic.fromDegrees(lng,lat,alt);
  var cartesian3=ellipsoid.cartographicToCartesian(cartographic);


二、 世界坐标转换为经纬度
1.var ellipsoid=viewer.scene.globe.ellipsoid;
  var cartesian3=new Cesium.cartesian3(x,y,z);
  var cartographic=ellipsoid.cartesianToCartographic(cartesian3);
  var lat=Cesium.Math.toDegrees(cartograhphic.latitude);
  var lng=Cesium.Math.toDegrees(cartograhpinc.longitude);
  var alt=cartographic.height;

2.Cartographic.fromCartesian

三、屏幕坐标和世界坐标相互转换
1.var pick1= new Cesium.Cartesian2(0,0);
  var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(pick1),viewer.scene);

2.Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, Cartesian3);

Cartesian3的方法和属性:
.fromSpherical函数:Converts the provided Spherical into Cartesian3 coordinates
                              把球形转化为C3坐标
.fromElements函数:Creates a Cartesian3 instance from x, y and z coordinates.
                              使用X/Y/Z坐标给C3赋值
.clone函数:Duplicates a Cartesian3 instance.
                             复制C3实例并返回
.fromCartesian4对象:Creates a Cartesian3 instance from an existing Cartesian4.  This simply takes the x, y, and z properties of the Cartesian4 and drops w.
                             函数方法与clone函数相同,即返回值为C3实例
.packedLength对象:The number of elements used to pack the object into an array.
                             返回值为3
.pack函数:Stores the provided instance into the provided array.
                             将提供的实例置入数组(可以为空)中,返回该数组
.unpack函数:Retrieves an instance from a packed array
                     从数组中根据位置检索一个实例并返回

array的数据结构:[ x , y , z , x , y , z , x , y , z , x ……]

.packArray函数:Flattens an array of Cartesian3s into an array of components.
                         由C3的数组转换为一维的数组,并返回
.unpackArray函数:Unpacks an array of cartesian components into an array of Cartesian3s.
                             由一维的数组转换为C3的数组,并返回

C3数组的数据结构:[C3_1 , C3_2 , C3_3 ……]

.fromArray对象:Creates a Cartesian3 from three consecutive elements in an array.
                         为unpack函数的返回值
.maximumComponent函数:Computes the value of the maximum component for the supplied Cartesian.
                                         计算C3中X/Y/Z的最大值并返回
.minimumComponent函数:Computes the value of the minimum component for the supplied Cartesian.
                                         计算C3中X/Y/Z的最小值并返回
.minimumByComponent函数:Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
                                            分别比较两个C3实例的X/Y/Z并返回一个各坐标均为最小的CS实例
.maximumByComponent函数:Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
                                            分别比较两个C3实例的X/Y/Z并返回一个各坐标均为最大的CS实例
.magnitudeSquared函数:Computes the provided Cartesian's squared magnitude.
                                     计算X/Y/Z的平方和并返回
.magnitude函数:Computes the Cartesian's magnitude (length).
                          进行magnitudeSquared后的根号计算并返回
.distance函数:Computes the distance between two points.
                       计算两个点之间的距离
.distanceSquared函数:Computes the squared distance between two points.  Comparing squared distances
                                  计算两点之间的距离的平方根
.normalize函数:Computes the normalized form of the supplied Cartesian.
                         计算成为统一的C3格式
.dot函数:Computes the dot (scalar) product of two Cartesians.(物理意义是什么?经常用到)
                计算两个Cartesian的点(标量)乘积
.multiplyComponents函数:Computes the componentwise product of two Cartesians.
                                        计算两个C3实例的乘积(分量积)后的C3实例
.divideComponents函数:Computes the componentwise quotient of two Cartesians.
                                     计算两个C3实例的相除(分量商)后的C3实例
.add函数:Computes the componentwise sum of two Cartesians.
                计算两个C3实例的相加(分量和)后的C3实例
.subtract函数:Computes the componentwise difference of two Cartesians.
                       计算两个C3实例的相减(分量差)后的C3实例
.multiplyByScalar函数:Multiplies the provided Cartesian componentwise by the provided scalar.
                                  计算C3实例与已知级别相乘并返回
.divideByScalar函数:Multiplies the provided Cartesian componentwise by the provided scalar.
                                  计算C3实例与已知级别相除并返回
.negate函数:Negates the provided Cartesian.
                    计算C3实例的相反数并返回
.abs函数:Computes the absolute value of the provided Cartesian.
                计算C3实例的绝对值并返回
.lerp函数:Computes the linear interpolation or extrapolation at t using the provided cartesians.
                根据t的值和两个C3实例(对t来说,一个对应的值为0,一个为1)进行内插或外推
.angleBetween函数:Returns the angle, in radians, between the provided Cartesians.
                               以弧度制单位返回两个C3实例间的角度
.mostOrthogonalAxis函数:Returns the axis that is most orthogonal to the provided Cartesian.(还不是很懂)
                                       返回与提供的C3实例正交的轴
.projectVector函数:Projects vector a onto vector b
                              把向量a投影到向量b上返回其结果
.equals函数:Compares the provided Cartesians componentwise and returns
                    比较两个C3实例是否相同
.equalsArray函数:private
                            比较C3实例是否与数组中某偏移量后的X/Y/Z相同
.equalsEpsilon函数:Compares the provided Cartesians componentwise and returns
                              根据一定的容忍度(误差圆)来判断两个C3实例是否相等
.cross函数:Computes the cross (outer) product of two Cartesians.(还不是很懂)
                  计算两个C3实例之间的叉积
.fromDegrees函数:Returns a Cartesian3 position from longitude and latitude values given in degrees.
                             由经纬度(角度单位)计算C3坐标并返回,通过调用fromRadians函数
.fromRadians函数:Returns a Cartesian3 position from longitude and latitude values given in radians.
                             由给定的经纬度(弧度单位)计算C3并返回
.fromDegreesArray函数:Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
                                     由给定的经纬度(角度单位)数组生成一个C3数组并返回
.fromRadiansArray函数:Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
                                    由给定的经纬度(弧度单位)数组生成一个C3数组并返回
.fromDegreesArrayHeights函数:Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
                                               由给定的坐标数据(角度单位)的数组生成一个C3数组并返回,数组数据结构如下
                                               [-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0 ……]
.fromRadiansArrayHeights函数:Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
                                              由给定的坐标数据(角度单位)的数组生成一个C3数组并返回,数组数据结构如下
                                              [-2.007, 0.645, 100000.0, -1.867, .575, 150000.0 ……]


.ZERO对象:An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
.UNIT_X对象:An immutable Cartesian3 instance initialized to (1.0, 0.0, 0.0).
.UNIT_Y对象:An immutable Cartesian3 instance initialized to (0.0, 1.0, 0.0).
.UNIT_Z对象:An immutable Cartesian3 instance initialized to (0.0, 0.0, 1.0).


.prototype.clone函数:Duplicates this Cartesian3 instance.
                                 调用clone函数,复制这个C3实例并返回
.prototype.equals函数:Compares this Cartesian against the provided Cartesian componentwise and returns
                                  调用equals函数,比较该实例与给定实例的相等关系
.prototype.equalsEpsilon函数:Compares this Cartesian against the provided Cartesian componentwise and returns
                                             调用equalsEpsilon函数,比较该实例域给定实例在误差范围内(给定的容忍度)的比较结果
.prototype.toString函数:Creates a string representing this Cartesian in the format '(x, y, z)'.