EclipseDetector.java

  1. /* Copyright 2002-2013 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.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  19. import org.apache.commons.math3.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 AbstractReconfigurableDetector<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 either an umbra detector or a penumbra detector
  52.      * with default 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.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  59.      * @deprecated as of 6.1 replaced by {@link #EclipseDetector(PVCoordinatesProvider,
  60.      * double, PVCoordinatesProvider, double)} followed by either a call to
  61.      * {@link #withUmbra()} or by a call to {@link #withPenumbra()}
  62.      */
  63.     @Deprecated
  64.     public EclipseDetector(final PVCoordinatesProvider occulted,  final double occultedRadius,
  65.                            final PVCoordinatesProvider occulting, final double occultingRadius,
  66.                            final boolean totalEclipse) {
  67.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD,
  68.              occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  69.     }

  70.     /** Build a new eclipse detector.
  71.      * <p>The new instance is either an umbra detector or a penumbra detector
  72.      * with default value for convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  73.      * <p>The maximal interval between eclipse checks should be smaller than
  74.      * the half duration of the minimal pass to handle, otherwise some short
  75.      * passes could be missed.</p>
  76.      * @param maxCheck maximal checking interval (s)
  77.      * @param occulted the body to be occulted
  78.      * @param occultedRadius the radius of the body to be occulted (m)
  79.      * @param occulting the occulting body
  80.      * @param occultingRadius the occulting body radius (m)
  81.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  82.      * @deprecated as of 6.1 replaced by {@link #EclipseDetector(double,
  83.      * PVCoordinatesProvider, double, PVCoordinatesProvider, double)} followed by
  84.      * either a call to {@link #withUmbra()} or by a call to {@link #withPenumbra()}
  85.      */
  86.     @Deprecated
  87.     public EclipseDetector(final double maxCheck,
  88.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  89.                            final PVCoordinatesProvider occulting, final double occultingRadius,
  90.                            final boolean totalEclipse) {
  91.         this(maxCheck, DEFAULT_THRESHOLD,
  92.              occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  93.     }

  94.     /** Build a new eclipse detector .
  95.      * <p>The new instance is either an umbra detector or a penumbra detector.</p>
  96.      * <p>The maximal interval between eclipse checks should be smaller than
  97.      * the half duration of the minimal pass to handle, otherwise some short
  98.      * passes could be missed.</p>
  99.      * @param maxCheck maximal checking interval (s)
  100.      * @param threshold convergence threshold (s)
  101.      * @param occulted the body to be occulted
  102.      * @param occultedRadius the radius of the body to be occulted (m)
  103.      * @param occulting the occulting body
  104.      * @param occultingRadius the occulting body radius (m)
  105.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  106.      * @deprecated as of 6.1 replaced by {@link #EclipseDetector(double, double,
  107.      * PVCoordinatesProvider, double, PVCoordinatesProvider, double)} followed by
  108.      * either a call to {@link #withUmbra()} or by a call to {@link #withPenumbra()}
  109.      */
  110.     @Deprecated
  111.     public EclipseDetector(final double maxCheck, final double threshold,
  112.                            final PVCoordinatesProvider occulted, final double occultedRadius,
  113.                            final PVCoordinatesProvider occulting, final double occultingRadius,
  114.                            final boolean totalEclipse) {
  115.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing<EclipseDetector>(),
  116.              occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  117.     }

  118.     /** Build a new eclipse detector.
  119.      * <p>The new instance is a total eclipse (umbra) detector with default
  120.      * values for maximal checking interval ({@link #DEFAULT_MAXCHECK})
  121.      * and convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  122.      * @param occulted the body to be occulted
  123.      * @param occultedRadius the radius of the body to be occulted (m)
  124.      * @param occulting the occulting body
  125.      * @param occultingRadius the occulting body radius (m)
  126.      */
  127.     public EclipseDetector(final PVCoordinatesProvider occulted,  final double occultedRadius,
  128.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  129.         this(DEFAULT_MAXCHECK, DEFAULT_THRESHOLD,
  130.              occulted, occultedRadius, occulting, occultingRadius);
  131.     }

  132.     /** Build a new eclipse detector.
  133.      * <p>The new instance is a total eclipse (umbra) detector with default
  134.      * value for convergence threshold ({@link #DEFAULT_THRESHOLD}).</p>
  135.      * <p>The maximal interval between eclipse checks should be smaller than
  136.      * the half duration of the minimal pass to handle, otherwise some short
  137.      * passes could be missed.</p>
  138.      * @param maxCheck maximal checking interval (s)
  139.      * @param occulted the body to be occulted
  140.      * @param occultedRadius the radius of the body to be occulted in meters
  141.      * @param occulting the occulting body
  142.      * @param occultingRadius the occulting body radius in meters
  143.      */
  144.     public EclipseDetector(final double maxCheck,
  145.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  146.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  147.         this(maxCheck, DEFAULT_THRESHOLD,
  148.              occulted, occultedRadius, occulting, occultingRadius);
  149.     }

  150.     /** Build a new eclipse detector.
  151.      * <p>The new instance is a total eclipse (umbra) detector.</p>
  152.      * <p>The maximal interval between eclipse checks should be smaller than
  153.      * the half duration of the minimal pass to handle, otherwise some short
  154.      * passes could be missed.</p>
  155.      * @param maxCheck maximal checking interval (s)
  156.      * @param threshold convergence threshold (s)
  157.      * @param occulted the body to be occulted
  158.      * @param occultedRadius the radius of the body to be occulted in meters
  159.      * @param occulting the occulting body
  160.      * @param occultingRadius the occulting body radius in meters
  161.      */
  162.     public EclipseDetector(final double maxCheck, final double threshold,
  163.                            final PVCoordinatesProvider occulted,  final double occultedRadius,
  164.                            final PVCoordinatesProvider occulting, final double occultingRadius) {
  165.         this(maxCheck, threshold, DEFAULT_MAX_ITER, new StopOnIncreasing<EclipseDetector>(),
  166.              occulted, occultedRadius, occulting, occultingRadius, true);
  167.     }

  168.     /** Private constructor with full parameters.
  169.      * <p>
  170.      * This constructor is private as users are expected to use the builder
  171.      * API with the various {@code withXxx()} methods to set up the instance
  172.      * in a readable manner without using a huge amount of parameters.
  173.      * </p>
  174.      * @param maxCheck maximum checking interval (s)
  175.      * @param threshold convergence threshold (s)
  176.      * @param maxIter maximum number of iterations in the event time search
  177.      * @param handler event handler to call at event occurrences
  178.      * @param occulted the body to be occulted
  179.      * @param occultedRadius the radius of the body to be occulted in meters
  180.      * @param occulting the occulting body
  181.      * @param occultingRadius the occulting body radius in meters
  182.      * @param totalEclipse umbra (true) or penumbra (false) detection flag
  183.      * @since 6.1
  184.      */
  185.     private EclipseDetector(final double maxCheck, final double threshold,
  186.                             final int maxIter, final EventHandler<EclipseDetector> handler,
  187.                             final PVCoordinatesProvider occulted,  final double occultedRadius,
  188.                             final PVCoordinatesProvider occulting, final double occultingRadius,
  189.                             final boolean totalEclipse) {
  190.         super(maxCheck, threshold, maxIter, handler);
  191.         this.occulted        = occulted;
  192.         this.occultedRadius  = FastMath.abs(occultedRadius);
  193.         this.occulting       = occulting;
  194.         this.occultingRadius = FastMath.abs(occultingRadius);
  195.         this.totalEclipse    = totalEclipse;
  196.     }

  197.     /** {@inheritDoc} */
  198.     @Override
  199.     protected EclipseDetector create(final double newMaxCheck, final double newThreshold,
  200.                                      final int nawMaxIter, final EventHandler<EclipseDetector> newHandler) {
  201.         return new EclipseDetector(newMaxCheck, newThreshold, nawMaxIter, newHandler,
  202.                                    occulted, occultedRadius, occulting, occultingRadius, totalEclipse);
  203.     }

  204.     /**
  205.      * Setup the detector to full umbra detection.
  206.      * <p>
  207.      * This will override a penumbra/umbra flag if it has been configured previously.
  208.      * </p>
  209.      * @return a new detector with updated configuration (the instance is not changed)
  210.      * @see #withPenumbra()
  211.      * @since 6.1
  212.      */
  213.     public EclipseDetector withUmbra() {
  214.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  215.                                    occulted, occultedRadius, occulting, occultingRadius,
  216.                                    true);
  217.     }

  218.     /**
  219.      * Setup the detector to penumbra detection.
  220.      * <p>
  221.      * This will override a penumbra/umbra flag if it has been configured previously.
  222.      * </p>
  223.      * @return a new detector with updated configuration (the instance is not changed)
  224.      * @see #withUmbra()
  225.      * @since 6.1
  226.      */
  227.     public EclipseDetector withPenumbra() {
  228.         return new EclipseDetector(getMaxCheckInterval(), getThreshold(), getMaxIterationCount(), getHandler(),
  229.                                    occulted, occultedRadius, occulting, occultingRadius,
  230.                                    false);
  231.     }

  232.     /** Get the occulting body.
  233.      * @return the occulting body
  234.      */
  235.     public PVCoordinatesProvider getOcculting() {
  236.         return occulting;
  237.     }

  238.     /** Get the occulting body radius (m).
  239.      * @return the occulting body radius
  240.      */
  241.     public double getOccultingRadius() {
  242.         return occultingRadius;
  243.     }

  244.     /** Get the occulted body.
  245.      * @return the occulted body
  246.      */
  247.     public PVCoordinatesProvider getOcculted() {
  248.         return occulted;
  249.     }

  250.     /** Get the occulted body radius (m).
  251.      * @return the occulted body radius
  252.      */
  253.     public double getOccultedRadius() {
  254.         return occultedRadius;
  255.     }

  256.     /** Get the total eclipse detection flag.
  257.      * @return the total eclipse detection flag (true for umbra events detection,
  258.      * false for penumbra events detection)
  259.      */
  260.     public boolean getTotalEclipse() {
  261.         return totalEclipse;
  262.     }

  263.     /** Compute the value of the switching function.
  264.      * This function becomes negative when entering the region of shadow
  265.      * and positive when exiting.
  266.      * @param s the current state information: date, kinematics, attitude
  267.      * @return value of the switching function
  268.      * @exception OrekitException if some specific error occurs
  269.      */
  270.     public double g(final SpacecraftState s) throws OrekitException {
  271.         final Vector3D pted = occulted.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  272.         final Vector3D ping = occulting.getPVCoordinates(s.getDate(), s.getFrame()).getPosition();
  273.         final Vector3D psat = s.getPVCoordinates().getPosition();
  274.         final Vector3D ps   = pted.subtract(psat);
  275.         final Vector3D po   = ping.subtract(psat);
  276.         final double angle  = Vector3D.angle(ps, po);
  277.         final double rs     = FastMath.asin(occultedRadius / ps.getNorm());
  278.         final double ro     = FastMath.asin(occultingRadius / po.getNorm());
  279.         return totalEclipse ? (angle - ro + rs) : (angle - ro - rs);
  280.     }

  281. }