try {
// Load TLE data
String line1 = "1 25544U 98067A 23235.51284918 .00014007 00000-0 25659-3 0 9995";
String line2 = "2 25544 51.6426 355.0105 0003727 342.0009 113.8232 15.49590945412235";
TLE tle = new TLE(line1, line2);
System.out.println(tle.getDate());
// Create TLE propagator
Propagator propagator = SGP4.selectExtrapolator(tle);
// Earth and frame
final Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
final BodyShape earth = new OneAxisEllipsoid(
Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
Constants.WGS84_EARTH_FLATTENING,
earthFrame);
// Station
final double longitude = FastMath.toRadians(77.33); // Replace with your longitude -75.0
final double latitude = FastMath.toRadians(28.58); // Replace with your latitude 28.58
final double altitude = 0.;
final GeodeticPoint station1 = new GeodeticPoint(latitude, longitude, altitude);
final TopocentricFrame sta1Frame = new TopocentricFrame(earth, station1, "station1");
// Event definition
final double maxCheck = 60.0; // checking elevation angle every 60 seconds
final double threshold = 0.001;
final double elevation = FastMath.toRadians(15.0);
final EventDetector sta1Visi =
new ElevationDetector(maxCheck, threshold, sta1Frame).
withConstantElevation(elevation).
withHandler((s, detector, increasing) -> {
System.out.println(" Visibility on " +
detector.getTopocentricFrame().getName() +
(increasing ? " begins at " : " ends at ") +
s.getDate());
return increasing ? Action.CONTINUE : Action.STOP;
});
// Add event to be detected
propagator.addEventDetector(sta1Visi);
// Propagate from the initial TLE epoch to the event or for the fixed duration
final AbsoluteDate initialDate = tle.getDate();
final SpacecraftState finalState = propagator.propagate(initialDate.shiftedBy(555000.));
System.out.println("Final state : " + finalState.getDate().durationFrom(initialDate));
// System.out.println("Final velocity : " + finalState.getPVCoordinates().getVelocity());
// Calculate and print latitude, longitude, and altitude
GeodeticPoint geodeticPoint = earth.transform(finalState.getPVCoordinates().getPosition(), earthFrame, finalState.getDate());
double latitudeRad = geodeticPoint.getLatitude();
double longitudeRad = geodeticPoint.getLongitude();
double altitudeMeters = geodeticPoint.getAltitude();
// double altitudeKm = altitudeMeters / 1000.0;
double altitudeMiles = altitudeMeters * 0.000621371;
double latitudeDeg = FastMath.toDegrees(latitudeRad);
double longitudeDeg = FastMath.toDegrees(longitudeRad);
System.out.println("Latitude: " + latitudeDeg + " degrees");
System.out.println("Longitude: " + longitudeDeg + " degrees");
System.out.println("Altitude: " + altitudeMiles + " miles");
}