基于JAVA开发的利用TLE数据计算卫星轨道六根数源码

1、TLE数据(Two Line Elements)

tle数据是描述卫星轨道的一种标准格式,由两行数字组成,格式如下

QIXIANG-001          
1 44940U 20001AC  23289.39944927  .00024096  00000+0  16308-2 0  9995
2 44940  53.0532 295.9515 0001371  97.1775 262.9370 15.06404965208194

废话不多说,下面直接上代码

2、使用Orekit计算轨道六根数

1、引入orekitjar包

在orkit官网Download下载对应版本的jar包,我下载的是最新版12.0.1,下载后将orekit-12.0.1.jar引入到项目中

2、引入Hipparchus依赖包,hipparchus可以通过maven依赖引入,一定要引入3.0以上版本,否则会报一个找不到类的错误

happarchus介绍参见官网About | Hipparchus

   <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-fitting</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-clustering</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-fft</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-filtering</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-geometry</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-ode</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-optim</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-stat</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.hipparchus</groupId>
            <artifactId>hipparchus-migration</artifactId>
            <version>3.0</version>
        </dependency>

3、计算轨道六根数

  public void calculateOrbitElement(String tle){
        File orekitData = new File("D:\\orekit-data");

        DataProvidersManager manager = DataContext.getDefault().getDataProvidersManager();
        manager.addProvider(new DirectoryCrawler(orekitData)); // 存放orekitdata路径
        String[] params = tle.split("\n");
        String line1= params[1];
        String line2= params[2];
        TLE tleObj = new TLE(line1,line2);
        TLEPropagator  tlePropagator= TLEPropagator.selectExtrapolator(tleObj);
        Orbit cartesianOrbit = tlePropagator.getInitialState().getOrbit(); // 笛卡尔轨道
        KeplerianOrbit keplerianOrbit = new KeplerianOrbit(cartesianOrbit);  // 转换为开普勒轨道
        System.out.println("半长轴:"+keplerianOrbit.getA());
        System.out.println("离心率:"+keplerianOrbit.getE());
        System.out.println("轨道倾角:"+keplerianOrbit.getI());
        System.out.println("升交点赤经:"+Math.toDegrees(keplerianOrbit.getRightAscensionOfAscendingNode())); // 弧度转化为度
        System.out.println("近地点幅角:"+Math.toDegrees(keplerianOrbit.getPerigeeArgument()));
        System.out.println("真近点角"+keplerianOrbit.getTrueAnomaly());
    }

orikit-data文件下载地址:https://gitlab.orekit.org/orekit/orekit-data/-/archive/master/orekit-data-master.zip

运行结果:

半长轴:6931700.6419055825
离心率:0.0012640703558907736
轨道倾角:0.9262838362266536
升交点赤经:-64.04849998651345
近地点幅角:52.248882667192056
真近点角-0.9119147488086196

真近点角范围是(0,2Π),这里计算出来为负是因为这里计算的范围是(-Π,Π),可以通过数学转换来实现

卫星的六根包括卫星的标识符、轨道倾角、升交点赤经、近地点参、平均运动和偏心率等信息。将这些信息转换为卫星的两行需要进行一定的计算和转换,涉及到一些学知识和公式。 以下是使用Java编写的卫星六根转换为两行的示例代码: ``` import java.text.DecimalFormat; public class SatelliteConverter { private static final double PI = 3.14159265358979323846; private static final double TWO_PI = 2.0 * PI; private static final double EARTH_RADIUS = 6378.135; private static final double GM = 398600.5; public static String convertToTwoLine(String name, double epoch, double i, double raan, double e, double w, double m) { DecimalFormat format = new DecimalFormat("0.00000000"); // 计算半长轴和平均角速度 double a = Math.pow(GM / (TWO_PI * (m / 86400.0)) * (m / 86400.0), 1.0 / 3.0); double n = TWO_PI / (m / 86400.0); // 计算轨道倾角 double sinI = Math.sin(i * PI / 180.0); double cosI = Math.cos(i * PI / 180.0); // 计算升交点赤经 double sinRAAN = Math.sin(raan * PI / 180.0); double cosRAAN = Math.cos(raan * PI / 180.0); double x = cosRAAN; double y = sinRAAN * cosI; double z = sinRAAN * sinI; double r = Math.sqrt(x * x + y * y); double raanRadians = r > 0.0 ? Math.acos(x / r) : 0.0; if (y < 0.0) { raanRadians = TWO_PI - raanRadians; } double raanDegrees = raanRadians * 180.0 / PI; // 计算近地点参 double sinW = Math.sin(w * PI / 180.0); double cosW = Math.cos(w * PI / 180.0); double cosE = e; double sinE = Math.sqrt(1 - cosE * cosE); double p = a * (1 - e * e); double rP = p / (1 + e * cosW); double rA = p / (1 - e * cosW); double h = Math.sqrt(rP * rA * GM); double trueAnomaly = m + w; double sinTrueAnomaly = Math.sin(trueAnomaly * PI / 180.0); double cosTrueAnomaly = Math.cos(trueAnomaly * PI / 180.0); double rVector = h * h / (GM * (1 + e * cosTrueAnomaly)); double xVector = rVector * cosTrueAnomaly; double yVector = rVector * sinTrueAnomaly; double pVector = xVector * cosRAAN + yVector * sinRAAN; double qVector = -xVector * sinRAAN + yVector * cosRAAN; double f = Math.atan2(z, r); double g = raanRadians; double k = f + w * PI / 180.0; double h2 = (pVector * Math.cos(k) + qVector * Math.sin(k)) / p; double sinU = sinW / sinE; double cosU = (cosE - cosW) / sinE; double u = Math.atan2(sinU, cosU); double p2 = p / EARTH_RADIUS; double q2 = 0.0; if (i != 0.0) { q2 = p2 * h2 * Math.sin(u); } double sinL = Math.sin(g + u); double cosL = Math.cos(g + u); double sinI2 = Math.sin(i * PI / 180.0); double cosI2 = Math.cos(i * PI / 180.0); double sinRAAN2 = Math.sin(raanRadians); double cosRAAN2 = Math.cos(raanRadians); double x2 = sinL * cosRAAN2 - cosL * sinRAAN2 * cosI2; double y2 = sinL * sinRAAN2 + cosL * cosRAAN2 * cosI2; double z2 = cosL * sinI2; double r2 = Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2); double latitude = Math.asin(z2 / r2) * 180.0 / PI; double longitude = Math.atan2(y2, x2) * 180.0 / PI; if (longitude < 0.0) { longitude += 360.0; } double altitude = (h - EARTH_RADIUS) / 1000.0; // 构造两行字符串 StringBuilder builder = new StringBuilder(); builder.append(name.trim()).append(" "); builder.append("1 ").append(format.format(epoch)).append(" "); builder.append(format.format(i)).append(" "); builder.append(format.format(raanDegrees)).append(" "); builder.append(format.format(e, 7)).append(" "); builder.append(format.format(w)).append(" "); builder.append(format.format(n)).append(" "); builder.append(format.format(latitude)).append(" "); builder.append(format.format(longitude)).append(" "); builder.append(format.format(altitude)).append(" "); builder.append("00000"); return builder.toString(); } } ``` 这是一个静态方法,将卫星的六根作为参传入,返回一个字符串,表示卫星的两行。 示例代码使用了一些常和公式,如地球半径、引力常GM、圆周率等。代码中的计算过程涉及到一些计算,如三角函、向量运算等。最终,代码将转换后的两行构造成一个字符串并返回。 请注意,代码中的计算过程可能存在一些精度误差和边界问题,需要据实际情况进行验证和调整。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值