(一)工程中加入依赖库orekit-12.1.1.jar,不然所需类无法引入,此外如果是maven项目还需要在pom中添加以下依赖
<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>
(二)需要准备 orekit-data,下载后,解压文件,将解压后的文件目录放到项目需要部署的某个目录,后续代码中需要通过文件路径读取
(三)经过上面两步骤后,运行环境准备完毕。下面直接上代码
计算一段时间内卫星的星下点经纬高。
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.orekit.time.TimeScale;
import org.orekit.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.hipparchus.util.FastMath;
import org.orekit.bodies.GeodeticPoint;
import org.orekit.bodies.OneAxisEllipsoid;
import org.orekit.data.DataContext;
import org.orekit.data.DirectoryCrawler;
import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.propagation.analytical.tle.TLE;
import org.orekit.propagation.analytical.tle.TLEPropagator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.IERSConventions;
import org.orekit.utils.PVCoordinates;
import java.net.HttpURLConnection;
import java.net.URL;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
@SpringBootTest
class TestApplicationTests {
@Autowired
private OrbitUtil orbitUtil;
@Test
void getOrbitPoint() throws Exception {
String startTime = "2024-07-17 14:06:00";
String endTime = "2024-07-18 14:06:00";
//俩行根数也可以按照本人的另外一个博客《在线获取卫星二行根数TLE》中调用api方式获取
String line1 = ""; //两行根数的line1
String line2 = ""; //两行根数的line2
String filePath = "E:\\lib\\orekit-data";
getSatInfo(filePath,line1,line2, TimeUtil.stringToDate(startTime),TimeUtil.stringToDate(endTime));
}
public void getSatInfo(String filePath,String line1, String line2, Date startDate, Date endDate) {
List<PositionLatLon> positionLatLons = new ArrayList();
// 本地orekit-data文件地址
File orekitData = new File(filePath);
DataContext.getDefault().getDataProvidersManager().addProvider(new DirectoryCrawler(orekitData));
TimeScale utc = TimeScalesFactory.getUTC();
TLE tle = new TLE(line1, line2);
TLEPropagator propagator = TLEPropagator.selectExtrapolator(tle);
//时间间隔步长:秒
int stepSize = 60;
//计算时间段由北京时间转为UTC时间
AbsoluteDate start = new AbsoluteDate(startDate, utc);
AbsoluteDate end = new AbsoluteDate(endDate, utc);
// 每隔stepSize秒,计算一次星下点
for (AbsoluteDate date = start; date.compareTo(end) <= 0; date = date.shiftedBy(stepSize)) {
//PV坐标系
PVCoordinates pvCoordinates = propagator.getPVCoordinates(date, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
//ECFF坐标系
Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, earthFrame);
//转为大地坐标系
GeodeticPoint geoPoint = earth.transform(pvCoordinates.getPosition(), earthFrame, date);
double lat = FastMath.toDegrees(geoPoint.getLatitude()); //卫星当前时刻的纬度 单位:度
double lon = FastMath.toDegrees(geoPoint.getLongitude()); //卫星当前时刻的经度 单位:度
double alt = geoPoint.getAltitude(); ///卫星当前时刻的高度 ,单位:米
String utcTime = date.toString(utc);
Date beijingDate = date.toDate(utc);
String beijingTime = TimeUtil.dateToString(beijingDate);
log.info("北京时间:{}, UTC时间:{}, 经度:{}°,纬度:{}°,高度:{}米",beijingTime,utcTime,lon,lat,alt);
}
}
}
(四) 结果验证
上面计算了一段时间内,每隔60秒一次的卫星经纬高坐标,将计算结果和STK中的结果进行对比后,发现结果高度一致,相差微乎其微。如果TSTK中使用的TLE和上述代码中一致的话,结果更接近。