LongitudeExtremumDetector.java

  1. /* Copyright 2002-2021 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.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.propagation.SpacecraftState;
  23. import org.orekit.propagation.events.handlers.EventHandler;
  24. import org.orekit.propagation.events.handlers.StopOnIncreasing;

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

  32.     /** Body on which the longitude is defined. */
  33.     private OneAxisEllipsoid body;

  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 longitude is defined
  39.      */
  40.     public LongitudeExtremumDetector(final OneAxisEllipsoid body) {
  41.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD, body);
  42.     }

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

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

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

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

  84.     /** Compute the value of the detection function.
  85.      * <p>
  86.      * The value is the spacecraft longitude time derivative.
  87.      * </p>
  88.      * @param s the current state information: date, kinematics, attitude
  89.      * @return spacecraft longitude time derivative
  90.      */
  91.     public double g(final SpacecraftState s) {

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

  95.         // longitude time derivative
  96.         return gp.getLongitude().getPartialDerivative(1);

  97.     }

  98. }