LatitudeCrossingDetector.java

  1. /* Copyright 2002-2022 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 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_MAXCHECK}) 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_MAXCHECK, 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(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing<LatitudeCrossingDetector>(),
  53.              body, latitude);
  54.     }

  55.     /** Private constructor with full parameters.
  56.      * <p>
  57.      * This constructor is private 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 maxCheck maximum checking interval (s)
  62.      * @param threshold convergence threshold (s)
  63.      * @param maxIter maximum number of iterations in the event time search
  64.      * @param handler event handler to call at event occurrences
  65.      * @param body body on which the latitude is defined
  66.      * @param latitude latitude to be crossed
  67.      */
  68.     private LatitudeCrossingDetector(final double maxCheck, final double threshold,
  69.                                      final int maxIter, final EventHandler<? super LatitudeCrossingDetector> handler,
  70.                                      final OneAxisEllipsoid body, final double latitude) {
  71.         super(maxCheck, threshold, maxIter, handler);
  72.         this.body     = body;
  73.         this.latitude = latitude;
  74.     }

  75.     /** {@inheritDoc} */
  76.     @Override
  77.     protected LatitudeCrossingDetector create(final double newMaxCheck, final double newThreshold,
  78.                                               final int newMaxIter,
  79.                                               final EventHandler<? super LatitudeCrossingDetector> newHandler) {
  80.         return new LatitudeCrossingDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  81.                                           body, latitude);
  82.     }

  83.     /** Get the body on which the geographic zone is defined.
  84.      * @return body on which the geographic zone is defined
  85.      */
  86.     public OneAxisEllipsoid getBody() {
  87.         return body;
  88.     }

  89.     /** Get the fixed latitude to be crossed (radians).
  90.      * @return fixed latitude to be crossed (radians)
  91.      */
  92.     public double getLatitude() {
  93.         return latitude;
  94.     }

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

  105.         // convert state to geodetic coordinates
  106.         final GeodeticPoint gp = body.transform(s.getPVCoordinates().getPosition(),
  107.                                                 s.getFrame(), s.getDate());

  108.         // latitude difference
  109.         return gp.getLatitude() - latitude;

  110.     }

  111. }