此功能已有一段時間沒有維護了,后面重新寫了一個。
有疑問可以給我留言或者聯系我的q 951973194;感謝大家的關注。
最近一直在弄關於衛星軌道及衛星掃描的功能,但是又沒提供軌道的具體坐標,后端也不提供軌道根數計算軌道坐標的接口。沒辦法,自己翻閱了好多資料,找出了一個比較冷門的方法,通過衛星的兩行參數,結合sgp4來模擬出一段時間的軌道坐標;這次就不曬出結合的方法了,只演示下如何模擬衛星掃描;
先曬出成果圖:
思路:這里我將衛星和下面的椎體分成了兩個entity,通過Cesium.SampledPositionProperty將坐標和時間進行關聯,通過插值算法,讓軌道平滑,最終達到了這個效果;
以下為代碼:
var viewer = new Cesium.Viewer('map');
var data = [];
data = [{
longitude: 116.405419,
dimension: 39.918034,
height: 700000,
time: 0
}, {
longitude: 115.2821,
dimension: 39.918145,
height: 700000,
time: 40
}, {
longitude: 114.497402,
dimension: 39.344641,
height: 700000,
time: 100
}, {
longitude: 107.942392,
dimension: 35.559967,
height: 700000,
time: 280
}, {
longitude: 106.549265,
dimension: 34.559967,
height: 700000,
time: 360
}, {
longitude: 95.2821,
dimension: 32.918145,
height: 700000,
time: 400
}, {
longitude: 94.497402,
dimension: 30.344641,
height: 700000,
time: 450
}, {
longitude: 87.942392,
dimension: 25.559967,
height: 700000,
time: 550
}, {
longitude: 66.549265,
dimension: 24.559967,
height: 700000,
time: 600
}];
// 起始時間
var start = Cesium.JulianDate.fromDate(new Date(2017, 7, 11));
// 結束時間
var stop = Cesium.JulianDate.addSeconds(start, 600, new Cesium.JulianDate());
// 設置始時鍾始時間
viewer.clock.startTime = start.clone();
// 設置時鍾當前時間
viewer.clock.currentTime = start.clone();
// 設置始終停止時間
viewer.clock.stopTime = stop.clone();
// 時間速率,數字越大時間過的越快
viewer.clock.multiplier = 10;
// 時間軸
viewer.timeline.zoomTo(start, stop);
// 循環執行
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
var property = computeFlight(data);
// 添加模型
var planeModel = viewer.entities.add({
// 和時間軸關聯
availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start: start,
stop: stop
})]),
position: property,
// 根據所提供的速度計算點
orientation: new Cesium.VelocityOrientationProperty(property),
// 模型數據
model: {
uri: '../gltfModel/weixin.gltf',
minimumPixelSize: 128
},
path: {
resolution: 1,
material: new Cesium.PolylineGlowMaterialProperty({
glowPower: .1,
color: Cesium.Color.YELLOW
}),
width: 10
}
});
planeModel.position.setInterpolationOptions({ //設定位置的插值算法
interpolationDegree: 5,
interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
});
var property2 = computeFlight2(data);
var entity_ty = viewer.entities.add({
availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start: start,
stop: stop
})]),
position: property2,
orientation: new Cesium.VelocityOrientationProperty(property2),
cylinder: {
HeightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
length: 700000,
topRadius: 0,
bottomRadius: 700000 / 2,
material: Cesium.Color.RED.withAlpha(.4),
outline: !0,
numberOfVerticalLines: 0,
outlineColor: Cesium.Color.RED.withAlpha(.8)
},
});
entity_ty.position.setInterpolationOptions({
interpolationDegree: 5,
interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
});
function computeFlight(source) {
var property = new Cesium.SampledPositionProperty();
for (var i = 0; i < source.length; i++) {
var time = Cesium.JulianDate.addSeconds(start, source[i].time, new Cesium.JulianDate);
var position = Cesium.Cartesian3.fromDegrees(source[i].longitude, source[i].dimension, source[i].height);
// 添加位置,和時間對應
property.addSample(time, position);
}
return property;
}
function computeFlight2(source) {
var property = new Cesium.SampledPositionProperty();
for (var i = 0; i < source.length; i++) {
var time = Cesium.JulianDate.addSeconds(start, source[i].time, new Cesium.JulianDate);
var position = Cesium.Cartesian3.fromDegrees(source[i].longitude, source[i].dimension, source[i].height / 2);
// 添加位置,和時間對應
property.addSample(time, position);
}
return property;
}
其中computeFlight 和 computeFlight2最大的區別就在於椎體的height的高度為衛星的一半;
本文轉自 https://blog.csdn.net/caozl1132/article/details/86287900,如有侵權,請聯系刪除。