当我们在cesium球体上添加一个3D坐标之后,我们以这个点的正方为0度,平时为俯仰视角的0度。然后这个视角经过视角的旋转和俯仰的变换后,大致会出现一个在地球的点也就是我们的视点。首先我将情况分为了两种,一是俯视的情况,二就是仰视的情况。
1.俯视的情况,我们知道俯仰角之后,相当于一个三角形我们知道了一个角和一个直角边求另一条直角边,然后往某个方向旋转后移动了多少距离:
let earthRadius = 6371000; // cesium地球的周长
const { lng, lat, height } = this.linePointList[this.drawIdx]; // 某个点的经纬度高度
let startingLatitude = this.$cesium.Math.toRadians(Number(lat)); //转换为弧度
let startingLongitude = this.$cesium.Math.toRadians(Number(lng)); //转换为弧度
let angle = Cesium.Math.toRadians(heading);
let radian = ((2 * Math.PI) / 360) * (90 + pitch); //这里的pitch就是俯视角度负数 那么三角形的已知角就是90 + pitch
let distance = height * Math.tan(radian); // 求出俯视角距离原点地面的距离
let deltaLatitude = (distance / earthRadius) * Math.cos(angle);
let deltaLongitude =
((distance / earthRadius) * Math.sin(angle)) /
Math.cos(startingLatitude);
let newLatitude = startingLatitude + deltaLatitude;
let newLongitude = startingLongitude + deltaLongitude;
newLatitude = this.$cesium.Math.toDegrees(newLatitude);
newLongitude = this.$cesium.Math.toDegrees(newLongitude); // 算出视角点距离某个方向移动多少距离之后的经纬度点高度为地形的高度
const heightDiff = await getHeigthByLngLat11(
this.$cesium,
window["lineEditMap"],
{ longitude: newLongitude, latitude: newLatitude }
);
1.仰视的情况,我们知道俯仰角之后,假设三角形的一条边为200,假设的原因是我们视角在往某个方向看的时候100 200 300的距离的情况下,他们的高度发生了变化但是100仰角的物体会挡住200或者300的物体,就相当于一个直角三角形相对于一个直角边做了几个平行线一样的道理,这样我们有角了,有了一个假设的距离,算出另个对角边之后加上原点的高度就是另个目标的高度了,这是一个很抽象的东西决堤看大家怎么去想去思考了:
let distance = 200;//假设距离
let deltaLatitude = (distance / earthRadius) * Math.cos(angle); //算出原点不加高度时候在地面的点距离假设距离之后的点的经纬度点
let deltaLongitude =
((distance / earthRadius) * Math.sin(angle)) /
Math.cos(startingLatitude);
let newLatitude = startingLatitude + deltaLatitude;
let newLongitude = startingLongitude + deltaLongitude;
newLatitude = this.$cesium.Math.toDegrees(newLatitude);
newLongitude = this.$cesium.Math.toDegrees(newLongitude);
let radian = ((2 * Math.PI) / 360) * pitch;//算出假设的点的高度
const start = this.positions[this.drawIdx];
let { height: pointHeight } = GetWGS84FromDKR(Cesium, start);
let newHeight = distance * Math.tan(radian) + pointHeight - 2.3; //算出假设的点的高度之后加上原点的高度地形之类的高就是假设点的3D坐标
return { lat: newLatitude, lng: newLongitude, height: newHeight };
以上就是本人在两种俯仰角情况旋转之后的视角方向的一个大致点,思路想法比较抽象,具体的想法怎么去优化还要靠自己去理解去减小误差之类的操作。