FieldLatitudeCrossingDetector.java

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

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

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

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

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

  68.     /** Protected constructor with full parameters.
  69.      * <p>
  70.      * This constructor is not public as users are expected to use the builder
  71.      * API with the various {@code withXxx()} methods to set up the instance
  72.      * in a readable manner without using a huge amount of parameters.
  73.      * </p>
  74.      * @param maxCheck maximum checking interval
  75.      * @param threshold convergence threshold (s)
  76.      * @param maxIter maximum number of iterations in the event time search
  77.      * @param handler event handler to call at event occurrences
  78.      * @param body body on which the latitude is defined
  79.      * @param latitude latitude to be crossed
  80.      */
  81.     protected FieldLatitudeCrossingDetector(
  82.             final FieldAdaptableInterval<T> maxCheck,
  83.             final T threshold,
  84.             final int maxIter,
  85.             final FieldEventHandler<T> handler,
  86.             final OneAxisEllipsoid body,
  87.             final double latitude) {
  88.         super(new FieldEventDetectionSettings<>(maxCheck, threshold, maxIter), handler);
  89.         this.body     = body;
  90.         this.latitude = latitude;
  91.     }

  92.     /** {@inheritDoc} */
  93.     @Override
  94.     protected FieldLatitudeCrossingDetector<T> create(
  95.             final FieldAdaptableInterval<T> newMaxCheck,
  96.             final T newThreshold,
  97.             final int newMaxIter,
  98.             final FieldEventHandler<T> newHandler) {
  99.         return new FieldLatitudeCrossingDetector<>(
  100.                 newMaxCheck, newThreshold, newMaxIter, newHandler, body, latitude);
  101.     }

  102.     /** Get the body on which the geographic zone is defined.
  103.      * @return body on which the geographic zone is defined
  104.      */
  105.     public OneAxisEllipsoid getBody() {
  106.         return body;
  107.     }

  108.     /** Get the fixed latitude to be crossed (radians).
  109.      * @return fixed latitude to be crossed (radians)
  110.      */
  111.     public double getLatitude() {
  112.         return latitude;
  113.     }

  114.     /** Compute the value of the detection function.
  115.      * <p>
  116.      * The value is the spacecraft latitude minus the fixed latitude to be crossed.
  117.      * It is positive if the spacecraft is northward and negative if it is southward
  118.      * with respect to the fixed latitude.
  119.      * </p>
  120.      * @param s the current state information: date, kinematics, attitude
  121.      * @return spacecraft latitude minus the fixed latitude to be crossed
  122.      */
  123.     public T g(final FieldSpacecraftState<T> s) {

  124.         // convert state to geodetic coordinates
  125.         final FieldGeodeticPoint<T> gp = body.transform(
  126.                 s.getPosition(),
  127.                 s.getFrame(),
  128.                 s.getDate());

  129.         // latitude difference
  130.         return gp.getLatitude().subtract(latitude);

  131.     }

  132. }