EclipseDetector.java

  1. /* Copyright 2002-2019 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.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.propagation.SpacecraftState;
  21. import org.orekit.propagation.events.handlers.EventHandler;
  22. import org.orekit.propagation.events.handlers.StopOnIncreasing;
  23. import org.orekit.utils.PVCoordinatesProvider;

  24. /** Finder for satellite eclipse related events.
  25.  * <p>This class finds eclipse events, i.e. satellite within umbra (total
  26.  * eclipse) or penumbra (partial eclipse).</p>
  27.  * <p>The default implementation behavior is to {@link
  28.  * org.orekit.propagation.events.handlers.EventHandler.Action#CONTINUE continue}
  29.  * propagation when entering the eclipse and to {@link
  30.  * org.orekit.propagation.events.handlers.EventHandler.Action#STOP stop} propagation
  31.  * when exiting the eclipse. This can be changed by calling {@link
  32.  * #withHandler(EventHandler)} after construction.</p>
  33.  * @see org.orekit.propagation.Propagator#addEventDetector(EventDetector)
  34.  * @author Pascal Parraud
  35.  */
  36. public class EclipseDetector extends AbstractDetector<EclipseDetector> {

  37.     /** Serializable UID. */
  38.     private static final long serialVersionUID = 20131118L;

  39.     /** Occulting body. */
  40.     private final PVCoordinatesProvider occulting;

  41.     /** Occulting body radius (m). */
  42.     private final double occultingRadius;

  43.     /** Occulted body. */
  44.     private final PVCoordinatesProvider occulted;

  45.     /** Occulted body radius (m). */
  46.     private final double occultedRadius;

  47.     /** Umbra, if true, or penumbra, if false, detection flag. */
  48.     private final boolean totalEclipse;

  49.     /** Build a new eclipse detector.
  50.      * <p>The new instance is a total eclipse (umbra) detector with default
  51.      * values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  52.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  53.      * @param occulted the body to be occulted
  54.      * @param occultedRadius the radius of the body to be occulted (m)
  55.      * @param occulting the occulting body
  56.      * @param occultingRadius the occulting body radius (m)
  57.      */
  58.     public EclipseDetector(final PVCoordinatesProvider occulted,  final double occultedRadius,
  59.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  60.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD,
  61.              occulted, occultedRadius, occulting, occultingRadius);
  62.     }

  63.     /** Build a new eclipse detector.
  64.      * <p>The new instance is a total eclipse (umbra) detector with default
  65.      * value for convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  66.      * <p>The maximal interval between eclipse checks should be smaller than
  67.      * the half duration of the minimal pass to handle, otherwise some short
  68.      * passes could be missed.</p>
  69.      * @param maxCheck maximal checking interval (s)
  70.      * @param occulted the body to be occulted
  71.      * @param occultedRadius the radius of the body to be occulted in meters
  72.      * @param occulting the occulting body
  73.      * @param occultingRadius the occulting body radius in meters
  74.      */
  75.     public EclipseDetector(final double maxCheck,
  76.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  77.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  78.         this(maxCheck, DEFAULT_THRESHOLD,
  79.              occulted, occultedRadius, occulting, occultingRadius);
  80.     }

  81.     /** Build a new eclipse detector.
  82.      * <p>The new instance is a total eclipse (umbra) detector.</p>
  83.      * <p>The maximal interval between eclipse checks should be smaller than
  84.      * the half duration of the minimal pass to handle, otherwise some short
  85.      * passes could be missed.</p>
  86.      * @param maxCheck maximal checking interval (s)
  87.      * @param threshold convergence threshold (s)
  88.      * @param occulted the body to be occulted
  89.      * @param occultedRadius the radius of the body to be occulted in meters
  90.      * @param occulting the occulting body
  91.      * @param occultingRadius the occulting body radius in meters
  92.      */
  93.     public EclipseDetector(final double maxCheck, final double threshold,
  94.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  95.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  96.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing<EclipseDetector>(),
  97.              occulted, occultedRadius, occulting, occultingRadius, true);
  98.     }

  99.     /** Private constructor with full parameters.
  100.      * <p>
  101.      * This constructor is private as users are expected to use the builder
  102.      * API with the various {@code withXxx()} methods to set up the instance
  103.      * in a readable manner without using a huge amount of parameters.
  104.      * </p>
  105.      * @param maxCheck maximum checking interval (s)
  106.      * @param threshold convergence threshold (s)
  107.      * @param maxIter maximum number of iterations in the event time search
  108.      * @param handler event handler to call at event occurrences
  109.      * @param occulted the body to be occulted
  110.      * @param occultedRadius the radius of the body to be occulted in meters
  111.      * @param occulting the occulting body
  112.      * @param occultingRadius the occulting body radius in meters
  113.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  114.      * @since 6.1
  115.      */
  116.     private EclipseDetector(final double maxCheck, final double threshold,
  117.                             final int maxIter, final EventHandler<? super EclipseDetector> handler,
  118.                             final PVCoordinatesProvider occulted,  final double occultedRadius,
  119.                             final PVCoordinatesProvider occulting, final double occultingRadius,
  120.                             final boolean totalEclipse) {
  121.         super(maxCheck, threshold, maxIter, handler);
  122.         this.occulted        = occulted;
  123.         this.occultedRadius  = FastMath.abs(occultedRadius);
  124.         this.occulting       = occulting;
  125.         this.occultingRadius = FastMath.abs(occultingRadius);
  126.         this.totalEclipse    = totalEclipse;
  127.     }

  128.     /** {@inheritDoc} */
  129.     @Override
  130.     protected EclipseDetector create(final double newMaxCheck, final double newThreshold,
  131.                                      final int nawMaxIter, final EventHandler<? super EclipseDetector> newHandler) {
  132.         return new EclipseDetector(newMaxCheck, newThreshold, nawMaxIter, newHandler,
  133.                                    occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  134.     }

  135.     /**
  136.      * Setup the detector to full umbra detection.
  137.      * <p>
  138.      * This will override a penumbra/umbra flag if it has been configured previously.
  139.      * </p>
  140.      * @return a new detector with updated configuration (the instance is not changed)
  141.      * @see #withPenumbra()
  142.      * @since 6.1
  143.      */
  144.     public EclipseDetector withUmbra() {
  145.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  146.                                    occulted, occultedRadius, occulting, occultingRadius,
  147.                                    true);
  148.     }

  149.     /**
  150.      * Setup the detector to penumbra detection.
  151.      * <p>
  152.      * This will override a penumbra/umbra flag if it has been configured previously.
  153.      * </p>
  154.      * @return a new detector with updated configuration (the instance is not changed)
  155.      * @see #withUmbra()
  156.      * @since 6.1
  157.      */
  158.     public EclipseDetector withPenumbra() {
  159.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  160.                                    occulted, occultedRadius, occulting, occultingRadius,
  161.                                    false);
  162.     }

  163.     /** Get the occulting body.
  164.      * @return the occulting body
  165.      */
  166.     public PVCoordinatesProvider getOcculting() {
  167.         return occulting;
  168.     }

  169.     /** Get the occulting body radius (m).
  170.      * @return the occulting body radius
  171.      */
  172.     public double getOccultingRadius() {
  173.         return occultingRadius;
  174.     }

  175.     /** Get the occulted body.
  176.      * @return the occulted body
  177.      */
  178.     public PVCoordinatesProvider getOcculted() {
  179.         return occulted;
  180.     }

  181.     /** Get the occulted body radius (m).
  182.      * @return the occulted body radius
  183.      */
  184.     public double getOccultedRadius() {
  185.         return occultedRadius;
  186.     }

  187.     /** Get the total eclipse detection flag.
  188.      * @return the total eclipse detection flag (true for umbra events detection,
  189.      * false for penumbra events detection)
  190.      */
  191.     public boolean getTotalEclipse() {
  192.         return totalEclipse;
  193.     }

  194.     /** Compute the value of the switching function.
  195.      * This function becomes negative when entering the region of shadow
  196.      * and positive when exiting.
  197.      * @param s the current state information: date, kinematics, attitude
  198.      * @return value of the switching function
  199.      */
  200.     public double g(final SpacecraftState s) {
  201.         final Vector3D pted = occulted.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  202.         final Vector3D ping = occulting.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  203.         final Vector3D psat = s.getPVCoordinates().getPosition();
  204.         final Vector3D ps   = pted.subtract(psat);
  205.         final Vector3D po   = ping.subtract(psat);
  206.         final double angle  = Vector3D.angle(ps, po);
  207.         final double rs     = FastMath.asin(occultedRadius / ps.getNorm());
  208.         if (Double.isNaN(rs)) {
  209.             return FastMath.PI;
  210.         }
  211.         final double ro     = FastMath.asin(occultingRadius / po.getNorm());
  212.         if (Double.isNaN(ro)) {
  213.             return -FastMath.PI;
  214.         }
  215.         return totalEclipse ? (angle - ro + rs) : (angle - ro - rs);
  216.     }

  217. }