BetaAngleDetector.java

  1. /* Copyright 2002-2025 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(EventDetectionSettings.getDefaultEventDetectionSettings(), 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 detectionSettings detection settings
  75.      * @param handler event handler to call at event occurrences
  76.      * @param betaAngleThreshold beta angle threshold (radians)
  77.      * @param celestialBodyProvider coordinate provider for the celestial provider
  78.      * @param inertialFrame inertial frame in which to compute the beta angle
  79.      */
  80.     protected BetaAngleDetector(final EventDetectionSettings detectionSettings, final EventHandler handler,
  81.                              final double betaAngleThreshold, final PVCoordinatesProvider celestialBodyProvider,
  82.                              final Frame inertialFrame) {
  83.         super(detectionSettings, handler);
  84.         this.betaAngleThreshold = betaAngleThreshold;
  85.         this.celestialBodyProvider = celestialBodyProvider;
  86.         this.inertialFrame = inertialFrame;
  87.     }

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

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

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

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

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

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

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

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

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

  161.     /** {@inheritDoc} */
  162.     @Override
  163.     protected BetaAngleDetector create(final EventDetectionSettings detectionSettings, final EventHandler newHandler) {
  164.         return new BetaAngleDetector(detectionSettings, newHandler,
  165.                 getBetaAngleThreshold(), getCelestialBodyProvider(), getInertialFrame());
  166.     }
  167. }