cesium求地球上两点的直线距离和求地表距离是不一样的,直接用3维向量计算的距离表示的是直线距离,计算地表距离需要借助EllipsoidGeodesic类
1.求两点的直线距离
let startPosition= new Cesium.Cartesian3.fromDegrees(110,30);
let endPosition= new Cesium.Cartesian3.fromDegrees(110,30.1);
let distance= Cesium.Cartesian3.distance(startPosition,endPosition);//求两点直线距离,单位为米
2.求两点的地表距离
let startPosition=new Cesium.Cartographic(110/(180/Math.PI),30/(180/Math.PI));
let endPosition=new Cesium.Cartographic(110/(180/Math.PI),30.1/(180/Math.PI));
let geodesic = new Cesium.EllipsoidGeodesic(startPosition,endPosition);
let distance = geodesic.surfaceDistance;//求地表距离,单位为米
3.按地表距离的比例求地表连线上的另外一点坐标
let startPosition=new Cesium.Cartographic(110/(180/Math.PI),30/(180/Math.PI));
let endPosition=new Cesium.Cartographic(110/(180/Math.PI),30.1/(180/Math.PI));
let geodesic = new Cesium.EllipsoidGeodesic(startPosition,endPosition);
let otherPosition=geodesic.interpolateUsingFraction(2,new Cesium.Cartographic());//求地表连线上2倍距离的点
4.求地表连线上,距离起点特定距离的地表点的坐标
let startPosition=new Cesium.Cartographic(110/(180/Math.PI),30/(180/Math.PI));
let endPosition=new Cesium.Cartographic(110/(180/Math.PI),30.1/(180/Math.PI));
let geodesic = new Cesium.EllipsoidGeodesic(startPosition,endPosition);
let otherPosition=geodesic.interpolateUsingSurfaceDistance(200,new Cesium.Cartographic());//求地表连线上距离起点200米的地表点的坐标
网友评论