ApsideDetector.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.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.ode.events.Action;
  20. import org.orekit.orbits.Orbit;
  21. import org.orekit.propagation.SpacecraftState;
  22. import org.orekit.propagation.events.handlers.EventHandler;
  23. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  24. import org.orekit.utils.PVCoordinates;

  25. /** Finder for apside crossing events.
  26.  * <p>This class finds apside crossing events (i.e. apogee or perigee crossing).</p>
  27.  * <p>The default implementation behavior is to {@link Action#CONTINUE continue}
  28.  * propagation at apogee crossing and to {@link Action#STOP stop} propagation
  29.  * at perigee crossing. This can be changed by calling
  30.  * {@link #withHandler(EventHandler)} after construction.</p>
  31.  * <p>Beware that apside detection will fail for almost circular orbits. If
  32.  * for example an apside detector is used to trigger an {@link
  33.  * org.orekit.forces.maneuvers.ImpulseManeuver ImpulseManeuver} and the maneuver
  34.  * change the orbit shape to circular, then the detector may completely fail just
  35.  * after the maneuver has been performed!</p>
  36.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  37.  * @author Luc Maisonobe
  38.  */
  39. public class ApsideDetector extends AbstractDetector<ApsideDetector> {

  40.     /** Build a new instance.
  41.      * <p>The Keplerian period is used only to set an upper bound for the
  42.      * max check interval to period/3 and to set the convergence threshold.</p>
  43.      * @param keplerianPeriod estimate of the Keplerian period
  44.      * @since 12.1
  45.      */
  46.     public ApsideDetector(final double keplerianPeriod) {
  47.         super(keplerianPeriod / 3, 1e-13 * keplerianPeriod, DEFAULT_MAX_ITER, new StopOnIncreasing());
  48.     }

  49.     /** Build a new instance.
  50.      * <p>The orbit is used only to set an upper bound for the
  51.      * max check interval to period/3 and to set the convergence
  52.      * threshold according to orbit size</p>
  53.      * @param orbit initial orbit
  54.      */
  55.     public ApsideDetector(final Orbit orbit) {
  56.         this(orbit.getKeplerianPeriod());
  57.     }

  58.     /** Build a new instance.
  59.      * <p>The orbit is used only to set an upper bound for the
  60.      * max check interval to period/3</p>
  61.      * @param threshold convergence threshold (s)
  62.      * @param orbit initial orbit
  63.      */
  64.     public ApsideDetector(final double threshold, final Orbit orbit) {
  65.         super(orbit.getKeplerianPeriod() / 3, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing());
  66.     }

  67.     /** Public constructor with full parameters.
  68.      * <p>
  69.      * This constructor is public because otherwise all accessible ones would require an orbit.
  70.      * </p>
  71.      * @param detectionSettings detection settings
  72.      * @param handler event handler to call at event occurrences
  73.      * @since 13.0
  74.      */
  75.     public ApsideDetector(final EventDetectionSettings detectionSettings, final EventHandler handler) {
  76.         super(detectionSettings, handler);
  77.     }

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     protected ApsideDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  81.         return new ApsideDetector(detectionSettings, newHandler);
  82.     }

  83.     /** Compute the value of the switching function.
  84.      * This function computes the dot product of the 2 vectors : position.velocity.
  85.      * @param s the current state information: date, kinematics, attitude
  86.      * @return value of the switching function
  87.      */
  88.     public double g(final SpacecraftState s) {
  89.         final PVCoordinates pv = s.getPVCoordinates();
  90.         return Vector3D.dotProduct(pv.getPosition(), pv.getVelocity());
  91.     }

  92. }