Hello everyone. first post here (and new to orekit!). I am trying to calculate TCA and MissDistance with TLE data from CelesTrack, but it calculates the values a bit incorrectly. how can I calculate the exact values without error?
package org.example;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.analytical.tle.TLE;
import org.orekit.propagation.analytical.tle.TLEPropagator;
import org.orekit.time.AbsoluteDate;
public class Main {
public static void main(String[] args) {
try {
// Initialize Orekit
InitializeOrekit.init();
// TLE data for Sat1
String tleLine1Sat1 = "1 45746U 20038S 24135.58388045 .00013219 00000+0 85889-3 0 9991";
String tleLine2Sat1 = "2 45746 53.0549 337.5672 0001521 101.0908 259.0253 15.08327573216090";
TLE tleSat1 = new TLE(tleLine1Sat1, tleLine2Sat1);
// TLE data for SL-12 R/B(AUX MOTOR)
String tleLine1Sat2 = "1 54760U 22175C 24136.21138098 .00004893 00000+0 32507-3 0 9990";
String tleLine2Sat2 = "2 54760 53.2150 142.7806 0001482 72.0039 288.1115 15.08864831 77592";
TLE tleSat2 = new TLE(tleLine1Sat2, tleLine2Sat2);
// Create TLE propagators
TLEPropagator propagatorTianmu1 = TLEPropagator.selectExtrapolator(tleSat1);
TLEPropagator propagatorSl12RB = TLEPropagator.selectExtrapolator(tleSat2);
// Set start date
AbsoluteDate startDate = tleSat1.getDate();
// Set time interval
AbsoluteDate endDate = startDate.shiftedBy(360 * 3600); // 15 days
// Find the time and distance of closest approach (TCA)
double minDistance = Double.MAX_VALUE;
AbsoluteDate tcaDate = null;
// Iterate over the time interval
AbsoluteDate currentDate = startDate;
while (currentDate.compareTo(endDate) <= 0) {
// Get the state of both spacecraft
SpacecraftState stateSat1 = propagatorTianmu1.propagate(currentDate);
SpacecraftState stateSat2 = propagatorSl12RB.propagate(currentDate);
// Get the position vectors
Vector3D positionSat1 = stateSat1.getPVCoordinates().getPosition();
Vector3D positionSat2 = stateSat2.getPVCoordinates().getPosition();
// Calculate the distance
double distance = Vector3D.distance(positionSat2, positionSat1);
// Check for minimum distance
if (distance < minDistance) {
minDistance = distance;
tcaDate = currentDate;
}
// Advance time
currentDate = currentDate.shiftedBy(0.02);
}
// Print the time and distance of closest approach
if (tcaDate != null) {
System.out.println("Closest Approach Time (TCA): " + tcaDate);
System.out.println("Minimum Distance (km): " + minDistance / 1000); // Distance in meters
} else {
System.out.println("TCA not found.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}