使用TLE(双行)根数计算出轨道数据以供Cesium使用

使用TLE(双行)根数计算出轨道数据以供Cesium使用

资源:

satellite.js:https://download.csdn.net/download/qq_41176306/19360956

核心代码:

import indexUmd from '../cesium/satellite.min.js';

const {
    propagate,
    twoline2satrec,
    gstime,
    eciToEcf,
} = indexUmd;

//  使用
const SampledPosition = this.getTlePositionData(tle.line1, tle.line2, this.viewer.clock.startTime, this.viewer.clock.stopTime, 1);

/**
 * 使用Satellite.js处理tle数据返回轨道信息
 * @param tle1 第一根tle
 * @param tle2 第二根tle
 * @param startTime 场景开始时间
 * @param stopTime 场景结束时间
 * @param step 步长
 * @returns SampledPosition对象
 */
getTlePositionData(tle1, tle2, startTime, stopTime, step = 10) {
    const SampledPosition = new Cesium.SampledPositionProperty();
    const start = new Date(startTime);
    const stop = new Date(stopTime);
    if (!tle1 || !tle2) return;
    const satrec = twoline2satrec(tle1, tle2);
    start.setTime(start.getTime() + step * 1000 * 0);
    let gmst = gstime(start);

    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    for (let i = 0; i < stop - start; i++) {
        start.setTime(start.getTime() + step * 1000 * i);
		gmst = gstime(start);
        const position = this._read(satrec, start, gmst);
        SampledPosition.addSample(Cesium.JulianDate.fromDate(start), position);
    }
    this._setInterpolation(SampledPosition);
    return SampledPosition;
}

_read(satrec, data, gmst) {
    const positionAndVelocity = propagate(satrec, data);
    const positionEci = positionAndVelocity.position;
    if (!positionEci) {
        console.error("获取位置错误")
        return;
    }

    const { x, y, z } = eciToEcf(positionEci, gmst);
    const position = Cesium.Cartesian3.fromElements(
        x * 1000,
        y * 1000,
        z * 1000
    );
    return position;
}

/**
 *插值算法:拉格朗日插值
 */
_setInterpolation(position) {
    const interpolationOptions = {
        interpolationDegree: 2,
        interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
    };
    position.setInterpolationOptions(interpolationOptions);
}

你可能感兴趣的:(Cesium,javascript,webgl,typescript,vue.js)