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.BodyShape;
  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 AbstractGeographicalDetector<LatitudeCrossingDetector> {

  30.     /** Fixed latitude to be crossed. */
  31.     private final double latitude;

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

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

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

  70.     /** {@inheritDoc} */
  71.     @Override
  72.     protected LatitudeCrossingDetector create(final EventDetectionSettings detectionSettings,
  73.                                               final EventHandler newHandler) {
  74.         return new LatitudeCrossingDetector(detectionSettings, newHandler, getBodyShape(), latitude);
  75.     }

  76.     /** Get the fixed latitude to be crossed (radians).
  77.      * @return fixed latitude to be crossed (radians)
  78.      */
  79.     public double getLatitude() {
  80.         return latitude;
  81.     }

  82.     /** Compute the value of the detection function.
  83.      * <p>
  84.      * The value is the spacecraft latitude minus the fixed latitude to be crossed.
  85.      * It is positive if the spacecraft is northward and negative if it is southward
  86.      * with respect to the fixed latitude.
  87.      * </p>
  88.      * @param s the current state information: date, kinematics, attitude
  89.      * @return spacecraft latitude minus the fixed latitude to be crossed
  90.      */
  91.     public double g(final SpacecraftState s) {

  92.         // convert state to geodetic coordinates
  93.         final GeodeticPoint gp = getBodyShape().transform(s.getPosition(),
  94.                                                 s.getFrame(), s.getDate());

  95.         // latitude difference
  96.         return gp.getLatitude() - latitude;

  97.     }

  98. }