EclipseDetector.java

  1. /* Copyright 2002-2018 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.errors.OrekitException;
  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.PVCoordinatesProvider;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  219. }