LatitudeExtremumDetector.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.analysis.differentiation.DerivativeStructure;
  19. import org.orekit.bodies.BodyShape;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.bodies.OneAxisEllipsoid;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.propagation.SpacecraftState;
  24. import org.orekit.propagation.events.handlers.EventHandler;
  25. import org.orekit.propagation.events.handlers.StopOnIncreasing;

  26. /** Detector for geographic latitude extremum.
  27.  * <p>This detector identifies when a spacecraft reaches its
  28.  * extremum latitudes with respect to a central body.</p>
  29.  * @author Luc Maisonobe
  30.  * @since 7.1
  31.  */
  32. public class LatitudeExtremumDetector extends AbstractDetector<LatitudeExtremumDetector> {

  33.     /** Serializable UID. */
  34.     private static final long serialVersionUID = 20150824L;

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

  37.     /** Build a new detector.
  38.      * <p>The new instance uses default values for maximal checking interval
  39.      * ({@link #DEFAULT_MAXCHECK}) and convergence threshold ({@link
  40.      * #DEFAULT_THRESHOLD}).</p>
  41.      * @param body body on which the latitude is defined
  42.      */
  43.     public LatitudeExtremumDetector(final OneAxisEllipsoid body) {
  44.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, body);
  45.     }

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

  56.     /** Private constructor with full parameters.
  57.      * <p>
  58.      * This constructor is private as users are expected to use the builder
  59.      * API with the various {@code withXxx()} methods to set up the instance
  60.      * in a readable manner without using a huge amount of parameters.
  61.      * </p>
  62.      * @param maxCheck maximum checking interval (s)
  63.      * @param threshold convergence threshold (s)
  64.      * @param maxIter maximum number of iterations in the event time search
  65.      * @param handler event handler to call at event occurrences
  66.      * @param body body on which the latitude is defined
  67.      */
  68.     private LatitudeExtremumDetector(final double maxCheck, final double threshold,
  69.                                      final int maxIter, final EventHandler<? super LatitudeExtremumDetector> handler,
  70.                                      final OneAxisEllipsoid body) {
  71.         super(maxCheck, threshold, maxIter, handler);
  72.         this.body = body;
  73.     }

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

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

  87.     /** Compute the value of the detection function.
  88.      * <p>
  89.      * The value is the spacecraft latitude time derivative.
  90.      * </p>
  91.      * @param s the current state information: date, kinematics, attitude
  92.      * @return spacecraft latitude time derivative
  93.      * @exception OrekitException if some specific error occurs
  94.      */
  95.     public double g(final SpacecraftState s) throws OrekitException {

  96.         // convert state to geodetic coordinates
  97.         final FieldGeodeticPoint<DerivativeStructure> gp =
  98.                         body.transform(s.getPVCoordinates(), s.getFrame(), s.getDate());

  99.         // latitude time derivative
  100.         return gp.getLatitude().getPartialDerivative(1);

  101.     }

  102. }