实现轨道之前,先来看几个公式
1、T=2π*√(a^3/GM)
2、T=2π*√(a^3/μ)
3、T=√4π²r³/GM
1和2都是卫星运动周期公式,3是天体运动周期,a表示卫星的轨道半长轴,μ表示行星的引力常数,同时又等于G*M,G是万有引力常数,M是中心天体质量,参考如下:
在cesium中,path定义为,描述Entity随时间移动时形成的路径的折线。故而,通过以下代码实现卫星轨道
let samp_icrf = new Cesium.SampledPositionProperty(
Cesium.ReferenceFrame.INERTIAL
);
samp_icrf.setInterpolationOptions({
interpolationDegree: 5,
interpolationAlgorithm: Cesium.LagrangePolynomialApproximation,
});
// sample-原始坐标值
sample.forEach(
(
{
epoch,
x_ICRF,
y_ICRF,
z_ICRF
}
) => {
const time = Cesium.JulianDate.fromDate(new Date(epoch));
samp_icrf.addSample(time, new Cesium.Cartesian3(x_ICRF, y_ICRF, z_ICRF));
// samp_q.addSample(time, new Cesium.Quaternion(x, y, z, w));
}
);
viewer.entities.add(
{
id: "sate_test",
model: {
uri: "model/wide.glb",
minimumPixelSize: 120,
maximumScale: 4800,
skipLevelOfDetail: true,
immediatelyLoadDesiredLevelOfDetail: true,
runAnimations: false,
incrementallyLoadTextures: false,
},
label: {
text: "sate_test",
font: "normal 30px 楷体",
fillColor: Cesium.Color.fromCssColorString("#ffffff"),
outlineColor: Cesium.Color.fromCssColorString("#000000"),
outlineWidth: 3,
pixelOffset: new Cesium.Cartesian2(0, -20), // 偏移量
showBackground: true,
backgroundColor:
Cesium.Color.fromCssColorString("#000000").withAlpha(0.5),
scaleByDistance: new Cesium.NearFarScalar(100000, 1.0, 10000000, 0.4),
backgroundPadding: new Cesium.Cartesian2(10, 10), //指定以像素为单位的水平和垂直背景填充padding
pixelOffsetScaleByDistance: new Cesium.NearFarScalar(
100000,
3.5,
30000000,
1
),
},
position: samp_icrf,
// orientation: new Cesium.CallbackProperty((time) => {
// const position = samp_icrf.getValue(time);
// const hpr = new Cesium.HeadingPitchRoll(
// Cesium.Math.toRadians(80),
// Cesium.Math.toRadians(-90),
// 0
// );
// return Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
// }, false),
path: {
resolution: 60,
material: Cesium.Color.GREEN,
leadTime: a ? calcT(a) : calcTByTle2(tle2),
trailTime: a ? calcT(a) : calcTByTle2(tle2),
width: 1,
},
});
samp_icrf是插值计算出来的惯性系坐标值,用于控制卫星模型移动,leadTime和trailTime可以理解为卫星的运行周期值,用到上面说的公式:
// 根据六要素,生成卫星轨道
function calcT(a) {
return 2 * Math.PI * Math.sqrt((a * a * a) / 3.986e14);
}
如果是tle卫星,则使用以下公式:
// 根据tle,生成卫星轨道
function calcTByTle2(line2) {
if (line2.length !== 69) {
return 0;
}
let nums = line2.substring(53, 63);
return 86400 / nums;
}
根据两行根计算卫星运动周期(86400 / 每天环绕地球圈数[tle第二行53-63])
tle含义参考:mars3d-tle参数含义
以上的sample是后台计算得到的数据,也可以使用satellite.js插件转换tle得到位置信息,然后根据时间推算一圈位置信息,再根据上面说的代码实现卫星轨道,如此少了发送请求,可以快速将tle建模至地球上。
satellite.js官方地址: github地址