BetaAngleDetector.java

  1. /* Copyright 2002-2024 Joseph Reed
  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.  * Joseph Reed 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.hipparchus.util.MathUtils;
  21. import org.orekit.annotation.DefaultDataContext;
  22. import org.orekit.bodies.CelestialBodyFactory;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.frames.FramesFactory;
  25. import org.orekit.propagation.SpacecraftState;
  26. import org.orekit.propagation.events.handlers.EventHandler;
  27. import org.orekit.propagation.events.handlers.StopOnEvent;
  28. import org.orekit.utils.PVCoordinatesProvider;
  29. import org.orekit.utils.TimeStampedPVCoordinates;

  30. /** Finder for beta angle crossing events.
  31.  * <p>Locate events when the beta angle (the angle between the orbit plane and the celestial body)
  32.  * crosses a threshold. The {@link #g(SpacecraftState)} function is negative when the beta angle
  33.  * is above the threshold and positive when the beta angle is below the threshold.</p>
  34.  * <p>The inertial frame provided must have it's origin centered at the satellite's orbit plane. The
  35.  * beta angle is computed as the angle between the celestial body's position in this frame with the
  36.  * satellite's orbital momentum vector.</p>
  37.  * <p>The default implementation behavior is to {@link Action#STOP stop}
  38.  * propagation at the first event date occurrence. This can be changed by calling
  39.  * {@link #withHandler(EventHandler)} after construction.</p>
  40.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  41.  * @author Joe Reed
  42.  * @since 12.1
  43.  */
  44. public class BetaAngleDetector extends AbstractDetector<BetaAngleDetector> {
  45.     /** Beta angle crossing threshold. */
  46.     private final double betaAngleThreshold;
  47.     /** Coordinate provider for the celestial body. */
  48.     private final PVCoordinatesProvider celestialBodyProvider;
  49.     /** Inertial frame in which beta angle is calculated. */
  50.     private final Frame inertialFrame;

  51.     /**Solar beta angle constructor.
  52.      * <p>This method uses the default data context, assigns the sun as the celestial
  53.      * body and uses GCRF as the inertial frame.</p>
  54.      * @param betaAngleThreshold beta angle threshold (radians)
  55.      */
  56.     @DefaultDataContext
  57.     public BetaAngleDetector(final double betaAngleThreshold) {
  58.         this(betaAngleThreshold, CelestialBodyFactory.getSun(), FramesFactory.getGCRF());
  59.     }

  60.     /** Class constructor.
  61.      * @param betaAngleThreshold beta angle threshold (radians)
  62.      * @param celestialBodyProvider coordinate provider for the celestial provider
  63.      * @param inertialFrame inertial frame in which to compute the beta angle
  64.      */
  65.     public BetaAngleDetector(final double betaAngleThreshold, final PVCoordinatesProvider celestialBodyProvider,
  66.             final Frame inertialFrame) {
  67.         this(AdaptableInterval.of(DEFAULT_MAXCHECK), DEFAULT_THRESHOLD, DEFAULT_MAX_ITER, new StopOnEvent(),
  68.                 betaAngleThreshold, celestialBodyProvider, inertialFrame);
  69.     }

  70.     /** Protected constructor with full parameters.
  71.      * <p>This constructor is not public as users are expected to use the builder
  72.      * API with the various {@code withXxx()} methods to set up the instance
  73.      * in a readable manner without using a huge amount of parameters.</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 betaAngleThreshold beta angle threshold (radians)
  79.      * @param celestialBodyProvider coordinate provider for the celestial provider
  80.      * @param inertialFrame inertial frame in which to compute the beta angle
  81.      */
  82.     protected BetaAngleDetector(final AdaptableInterval maxCheck, final double threshold,
  83.                              final int maxIter, final EventHandler handler,
  84.                              final double betaAngleThreshold, final PVCoordinatesProvider celestialBodyProvider,
  85.                              final Frame inertialFrame) {
  86.         super(maxCheck, threshold, maxIter, handler);
  87.         this.betaAngleThreshold = betaAngleThreshold;
  88.         this.celestialBodyProvider = celestialBodyProvider;
  89.         this.inertialFrame = inertialFrame;
  90.     }

  91.     /** Coordinate provider for the celestial body.
  92.      * @return celestial body's coordinate provider
  93.      */
  94.     public PVCoordinatesProvider getCelestialBodyProvider() {
  95.         return this.celestialBodyProvider;
  96.     }

  97.     /** The inertial frame in which beta angle is computed.
  98.      * @return the inertial frame
  99.      */
  100.     public Frame getInertialFrame() {
  101.         return this.inertialFrame;
  102.     }

  103.     /** The beta angle threshold (radians).
  104.      * @return the beta angle threshold (radians)
  105.      */
  106.     public double getBetaAngleThreshold() {
  107.         return this.betaAngleThreshold;
  108.     }

  109.     /** Create a new instance with the provided coordinate provider.
  110.      * <p>This method does not change the current instance.</p>
  111.      * @param newProvider the new coordinate provider
  112.      * @return the new detector instance
  113.      */
  114.     public BetaAngleDetector withCelestialProvider(final PVCoordinatesProvider newProvider) {
  115.         return new BetaAngleDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(),
  116.                 getHandler(), getBetaAngleThreshold(), newProvider, getInertialFrame());
  117.     }

  118.     /** Create a new instance with the provided beta angle threshold.
  119.      * <p>This method does not change the current instance.</p>
  120.      * @param newBetaAngleThreshold the beta angle threshold (radians)
  121.      * @return the new detector instance
  122.      */
  123.     public BetaAngleDetector withBetaThreshold(final double newBetaAngleThreshold) {
  124.         return new BetaAngleDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(),
  125.                 getHandler(), newBetaAngleThreshold, getCelestialBodyProvider(), getInertialFrame());
  126.     }

  127.     /** Create a new instance with the provided inertial frame.
  128.      * <p>This method does not change the current instance.</p>
  129.      * @param newFrame the inertial frame
  130.      * @return the new detector instance
  131.      */
  132.     public BetaAngleDetector withInertialFrame(final Frame newFrame) {
  133.         return new BetaAngleDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(),
  134.                 getHandler(), getBetaAngleThreshold(), getCelestialBodyProvider(), newFrame);
  135.     }

  136.     /** {@inheritDoc} */
  137.     @Override
  138.     public double g(final SpacecraftState s) {
  139.         final double beta = calculateBetaAngle(s, celestialBodyProvider, inertialFrame);
  140.         return betaAngleThreshold - beta;
  141.     }

  142.     /**Calculate the beta angle between the orbit plane and the celestial body.
  143.      * <p>This method computes the beta angle using the frame from the spacecraft state.</p>
  144.      * @param state spacecraft state
  145.      * @param celestialBodyProvider celestial body coordinate provider
  146.      * @return the beta angle (radians)
  147.      */
  148.     public static double calculateBetaAngle(final SpacecraftState state,
  149.             final PVCoordinatesProvider celestialBodyProvider) {
  150.         return calculateBetaAngle(state, celestialBodyProvider, state.getFrame());
  151.     }

  152.     /**Calculate the beta angle between the orbit plane and the celestial body.
  153.      * @param state spacecraft state
  154.      * @param celestialBodyProvider celestial body coordinate provider
  155.      * @param frame inertial frame in which beta angle will be computed
  156.      * @return the beta angle (radians)
  157.      */
  158.     public static double calculateBetaAngle(final SpacecraftState state,
  159.             final PVCoordinatesProvider celestialBodyProvider, final Frame frame) {
  160.         final Vector3D celestialP = celestialBodyProvider.getPosition(state.getDate(), frame);
  161.         final TimeStampedPVCoordinates pv = state.getPVCoordinates(frame);
  162.         return MathUtils.SEMI_PI - Vector3D.angle(celestialP, pv.getMomentum());
  163.     }

  164.     /** {@inheritDoc} */
  165.     @Override
  166.     protected BetaAngleDetector create(final AdaptableInterval newMaxCheck, final double newThreshold,
  167.             final int newMaxIter, final EventHandler newHandler) {
  168.         return new BetaAngleDetector(newMaxCheck, newThreshold, newMaxIter, newHandler,
  169.                 getBetaAngleThreshold(), getCelestialBodyProvider(), getInertialFrame());
  170.     }
  171. }