Zone area defined on earth

now I want to define a satellite and a ground area, and obtain the time period of the satellite’s sub satellite point trajectory in the ground area. How do I write the specific code?
I already below source code has some mistakes, could you give me the specific code.
source code:
import java.util.Locale;
import org.hipparchus.geometry.euclidean.threed.Vector3D;
import org.hipparchus.geometry.spherical.twod.SphericalPolygonsSet;
import org.hipparchus.util.FastMath;
import org.orekit.bodies.BodyShape;
import org.orekit.bodies.GeodeticPoint;
import org.orekit.bodies.OneAxisEllipsoid;
import org.orekit.errors.OrekitException;
import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.orbits.KeplerianOrbit;
import org.orekit.orbits.Orbit;
import org.orekit.propagation.Propagator;
import org.orekit.propagation.SpacecraftState;
import org.orekit.propagation.analytical.KeplerianPropagator;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.Constants;
import org.orekit.utils.IERSConventions;
import org.orekit.utils.PVCoordinates;

/** Orekit tutorial for special event detection.

  • This tutorial shows how to easily check for visibility between a satellite and a ground station.
  • @author Pascal Parraud
    public class RectangularRegionOnEarth {/
    * Private constructor for utility class. /
    private RectangularRegionOnEarth() {
    // empty
    * Program entry point.
    • @param args program arguments (unused here)
      public static void main(final String args) {
      try {
      // configure Orekit
      final File home = new File(System.getProperty(“user.home”));
      final File orekitData = new File(home, “orekit-data”);
      if (!orekitData.exists()) {
      System.err.format(Locale.US, “Failed to find %s folder%n”,
      System.err.format(Locale.US, “You need to download %s from %s, unzip it in %s and rename it ‘orekit-data’ for this tutorial to work%n”,
      “”, “”,
      final DataProvidersManager manager = DataContext.getDefault().getDataProvidersManager();
      manager.addProvider(new DirectoryCrawler(orekitData));
 //  Initial state definition : date, orbit
 final AbsoluteDate initialDate = new AbsoluteDate(2023, 10, 26, 8, 00, 00.000, TimeScalesFactory.getUTC());
 final double mu =  3.986004415e+14; // gravitation coefficient
 final Frame inertialFrame = FramesFactory.getEME2000(); // inertial frame for orbit definition
 final Vector3D position  = new Vector3D(-7518565.475, 4279265.668, 4816446.308);
 final Vector3D velocity  = new Vector3D(-5463.904, -5533.9672, 50.719);
 final PVCoordinates pvCoordinates = new PVCoordinates(position, velocity);
 final Orbit initialOrbit = new KeplerianOrbit(pvCoordinates, inertialFrame, initialDate, mu);

 // Propagator : consider a simple Keplerian motion 
 final Propagator kepler = new KeplerianPropagator(initialOrbit);

 // Earth and frame
 final Frame earthFrame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
 final BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,

 GeodeticPoint point1 = new GeodeticPoint(Math.toRadians(0), Math.toRadians(30), 0.0);
 GeodeticPoint point2 = new GeodeticPoint(Math.toRadians(30), Math.toRadians(30), 0.0);
 GeodeticPoint point3 = new GeodeticPoint(Math.toRadians(30), Math.toRadians(0), 0.0);
 GeodeticPoint point4 = new GeodeticPoint(Math.toRadians(0), Math.toRadians(0), 0.0);

 // 创建表示地面区域的SphericalPolygonsSet
 SphericalPolygonsSet region = EllipsoidTessellator.buildSimpleZone(1.0e-10, point1, point2, point3, point4);

 // Event definition
 final double maxcheck  = 60;
 final double threshold =  0.001;
 final double elevation = FastMath.toRadians(0.0);
 final GeographicZoneDetector zoneDetector = new GeographicZoneDetector(maxcheck, threshold, earth, region, elevation)
 		.withHandler((s, detector, increasing) -> {
             if (increasing) {
                 System.out.println("Visibility begins at " + s.getDate());
             } else {
                 System.out.println("Visibility ends at " + s.getDate());
             return Action.CONTINUE; // Continue processing the event

 // Add event to be detected

 // Propagate from the initial date to the first raising or for the fixed duration
 final SpacecraftState finalState = kepler.propagate(initialDate.shiftedBy(360000.));

 System.out.println(" Final state : " + finalState.getDate().durationFrom(initialDate));

} catch (OrekitException oe) {


Replace if (increasing) by if (!increasing)