FieldLatitudeCrossingDetector.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.hipparchus.Field;
  19. import org.hipparchus.CalculusFieldElement;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.bodies.OneAxisEllipsoid;
  22. import org.orekit.propagation.FieldSpacecraftState;
  23. import org.orekit.propagation.events.handlers.FieldEventHandler;
  24. import org.orekit.propagation.events.handlers.FieldStopOnIncreasing;
  25. import org.orekit.propagation.events.intervals.FieldAdaptableInterval;

  26. /** Detector for geographic latitude crossing.
  27.  * <p>This detector identifies when a spacecraft crosses a fixed
  28.  * latitude with respect to a central body.</p>
  29.  * @author Luc Maisonobe
  30.  * @author Evan Ward
  31.  * @since 9.3
  32.  * @param <T> type of the field elements
  33.  */
  34. public class FieldLatitudeCrossingDetector <T extends CalculusFieldElement<T>>
  35.         extends FieldAbstractDetector<FieldLatitudeCrossingDetector<T>, T> {

  36.     /** Body on which the latitude is defined. */
  37.     private final OneAxisEllipsoid body;

  38.     /** Fixed latitude to be crossed. */
  39.     private final double latitude;

  40.     /** Build a new detector.
  41.      * <p>The new instance uses default values for maximal checking interval
  42.      * ({@link #DEFAULT_MAX_CHECK}) and convergence threshold ({@link
  43.      * #DEFAULT_THRESHOLD}).</p>
  44.      * @param field the type of numbers to use.
  45.      * @param body body on which the latitude is defined
  46.      * @param latitude latitude to be crossed
  47.      */
  48.     public FieldLatitudeCrossingDetector(final Field<T> field,
  49.                                          final OneAxisEllipsoid body,
  50.                                          final double latitude) {
  51.         this(new FieldEventDetectionSettings<>(field, EventDetectionSettings.getDefaultEventDetectionSettings()),
  52.                 new FieldStopOnIncreasing<>(), body, latitude);
  53.     }

  54.     /** Build a detector.
  55.      * @param maxCheck maximal checking interval (s)
  56.      * @param threshold convergence threshold (s)
  57.      * @param body body on which the latitude is defined
  58.      * @param latitude latitude to be crossed
  59.      */
  60.     public FieldLatitudeCrossingDetector(final T maxCheck,
  61.                                          final T threshold,
  62.                                          final OneAxisEllipsoid body,
  63.                                          final double latitude) {
  64.         this(new FieldEventDetectionSettings<>(FieldAdaptableInterval.of(maxCheck.getReal()), threshold, DEFAULT_MAX_ITER),
  65.                 new FieldStopOnIncreasing<>(), body, latitude);
  66.     }

  67.     /** Protected constructor with full parameters.
  68.      * <p>
  69.      * This constructor is not public as users are expected to use the builder
  70.      * API with the various {@code withXxx()} methods to set up the instance
  71.      * in a readable manner without using a huge amount of parameters.
  72.      * </p>
  73.      * @param detectionSettings event detection settings
  74.      * @param handler event handler to call at event occurrences
  75.      * @param body body on which the latitude is defined
  76.      * @param latitude latitude to be crossed
  77.      * @since 13.0
  78.      */
  79.     protected FieldLatitudeCrossingDetector(
  80.             final FieldEventDetectionSettings<T> detectionSettings,
  81.             final FieldEventHandler<T> handler,
  82.             final OneAxisEllipsoid body,
  83.             final double latitude) {
  84.         super(detectionSettings, handler);
  85.         this.body     = body;
  86.         this.latitude = latitude;
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     protected FieldLatitudeCrossingDetector<T> create(
  91.             final FieldEventDetectionSettings<T> detectionSettings,
  92.             final FieldEventHandler<T> newHandler) {
  93.         return new FieldLatitudeCrossingDetector<>(detectionSettings, newHandler, body, latitude);
  94.     }

  95.     /** Get the body on which the geographic zone is defined.
  96.      * @return body on which the geographic zone is defined
  97.      */
  98.     public OneAxisEllipsoid getBody() {
  99.         return body;
  100.     }

  101.     /** Get the fixed latitude to be crossed (radians).
  102.      * @return fixed latitude to be crossed (radians)
  103.      */
  104.     public double getLatitude() {
  105.         return latitude;
  106.     }

  107.     /** Compute the value of the detection function.
  108.      * <p>
  109.      * The value is the spacecraft latitude minus the fixed latitude to be crossed.
  110.      * It is positive if the spacecraft is northward and negative if it is southward
  111.      * with respect to the fixed latitude.
  112.      * </p>
  113.      * @param s the current state information: date, kinematics, attitude
  114.      * @return spacecraft latitude minus the fixed latitude to be crossed
  115.      */
  116.     public T g(final FieldSpacecraftState<T> s) {

  117.         // convert state to geodetic coordinates
  118.         final FieldGeodeticPoint<T> gp = body.transform(
  119.                 s.getPosition(),
  120.                 s.getFrame(),
  121.                 s.getDate());

  122.         // latitude difference
  123.         return gp.getLatitude().subtract(latitude);

  124.     }

  125. }