LatitudeCrossingDetector.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.events;

  18. import org.orekit.bodies.OneAxisEllipsoid;
  19. import org.orekit.bodies.GeodeticPoint;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnIncreasing;

  23. /** Detector for geographic latitude crossing.
  24.  * <p>This detector identifies when a spacecraft crosses a fixed
  25.  * latitude with respect to a central body.</p>
  26.  * @author Luc Maisonobe
  27.  * @since 7.1
  28.  */
  29. public class LatitudeCrossingDetector extends AbstractDetector<LatitudeCrossingDetector> {

  30.     /** Body on which the latitude is defined. */
  31.     private final OneAxisEllipsoid body;

  32.     /** Fixed latitude to be crossed. */
  33.     private final double latitude;

  34.     /** Build a new detector.
  35.      * <p>The new instance uses default values for maximal checking interval
  36.      * ({@link #DEFAULT_MAX_CHECK}) and convergence threshold ({@link
  37.      * #DEFAULT_THRESHOLD}).</p>
  38.      * @param body body on which the latitude is defined
  39.      * @param latitude latitude to be crossed
  40.      */
  41.     public LatitudeCrossingDetector(final OneAxisEllipsoid body, final double latitude) {
  42.         this(DEFAULT_MAX_CHECK, DEFAULT_THRESHOLD, body, latitude);
  43.     }

  44.     /** Build a detector.
  45.      * @param maxCheck maximal checking interval (s)
  46.      * @param threshold convergence threshold (s)
  47.      * @param body body on which the latitude is defined
  48.      * @param latitude latitude to be crossed
  49.      */
  50.     public LatitudeCrossingDetector(final double maxCheck, final double threshold,
  51.                                     final OneAxisEllipsoid body, final double latitude) {
  52.         this(new EventDetectionSettings(maxCheck, threshold, DEFAULT_MAX_ITER), new StopOnIncreasing(),
  53.              body, latitude);
  54.     }

  55.     /** Protected constructor with full parameters.
  56.      * <p>
  57.      * This constructor is not public as users are expected to use the builder
  58.      * API with the various {@code withXxx()} methods to set up the instance
  59.      * in a readable manner without using a huge amount of parameters.
  60.      * </p>
  61.      * @param detectionSettings event detection settings
  62.      * @param handler event handler to call at event occurrences
  63.      * @param body body on which the latitude is defined
  64.      * @param latitude latitude to be crossed
  65.      * @since 13.0
  66.      */
  67.     protected LatitudeCrossingDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  68.                                        final OneAxisEllipsoid body, final double latitude) {
  69.         super(detectionSettings, handler);
  70.         this.body     = body;
  71.         this.latitude = latitude;
  72.     }

  73.     /** {@inheritDoc} */
  74.     @Override
  75.     protected LatitudeCrossingDetector create(final EventDetectionSettings detectionSettings,
  76.                                               final EventHandler newHandler) {
  77.         return new LatitudeCrossingDetector(detectionSettings, newHandler, body, latitude);
  78.     }

  79.     /** Get the body on which the geographic zone is defined.
  80.      * @return body on which the geographic zone is defined
  81.      */
  82.     public OneAxisEllipsoid getBody() {
  83.         return body;
  84.     }

  85.     /** Get the fixed latitude to be crossed (radians).
  86.      * @return fixed latitude to be crossed (radians)
  87.      */
  88.     public double getLatitude() {
  89.         return latitude;
  90.     }

  91.     /** Compute the value of the detection function.
  92.      * <p>
  93.      * The value is the spacecraft latitude minus the fixed latitude to be crossed.
  94.      * It is positive if the spacecraft is northward and negative if it is southward
  95.      * with respect to the fixed latitude.
  96.      * </p>
  97.      * @param s the current state information: date, kinematics, attitude
  98.      * @return spacecraft latitude minus the fixed latitude to be crossed
  99.      */
  100.     public double g(final SpacecraftState s) {

  101.         // convert state to geodetic coordinates
  102.         final GeodeticPoint gp = body.transform(s.getPosition(),
  103.                                                 s.getFrame(), s.getDate());

  104.         // latitude difference
  105.         return gp.getLatitude() - latitude;

  106.     }

  107. }