我正在将平面实体添加到铯中,如下所示:
let position = Cesium.Cartesian3.fromDegrees(long, lat, alt)
let planeEntity = this.viewer.entities.add({
position : position,
model : {
uri : './assets/cesium/Cesium_Air.glb',
minimumPixelSize : 64
}
});
我实时获得飞机位置,每次到达位置我都会这样做:
planeEntity.position = Cesium.Cartesian3.fromDegrees(long, lat, alt)
然后飞机移至该位置。
我想将机头旋转到正确的位置(如果飞机向上飞行,机头不能向左移动),
如何计算航向2的位置? (当前位置和下一个位置)
谢谢 拉里
答案 0 :(得分:0)
我在这里找到了解决方案: [Calculate bearing between 2 points with javascript
// Converts from degrees to radians.
toRadians(degrees) {
return degrees * Math.PI / 180;
}
// Converts from radians to degrees.
toDegrees(radians) {
return radians * 180 / Math.PI;
}
bearing(startLat, startLng, destLat, destLng){
startLat = this.toRadians(startLat);
startLng = this.toRadians(startLng);
destLat = this.toRadians(destLat);
destLng = this.toRadians(destLng);
let y = Math.sin(destLng - startLng) * Math.cos(destLat);
let x = Math.cos(startLat) * Math.sin(destLat) - Math.sin(startLat) * Math.cos(destLat) * Math.cos(destLng - startLng);
let brng = Math.atan2(y, x);
let brngDgr = this.toDegrees(brng);
return (brngDgr + 360) % 360;
}
答案 1 :(得分:0)
Cesium 方式基于 Larry ckey 的回答:
import * as Cesium from 'cesium';
const calculateBearing = (startPoint, endPoint) => {
const start = Cesium.Cartographic.fromCartesian(startPoint);
const end = Cesium.Cartographic.fromCartesian(endPoint);
const y = Math.sin(end.longitude - start.longitude) * Math.cos(end.latitude);
const x =
Math.cos(start.latitude) * Math.sin(end.latitude) -
Math.sin(start.latitude) * Math.cos(end.latitude) *
Math.cos(end.longitude - start.longitude);
const bearing = Math.atan2(y, x);
return Cesium.Math.toDegrees(bearing);
}