CylindricalShadowEclipseDetector.java

  1. /* Copyright 2022-2025 Romain Serra
  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.  * 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.utils.PVCoordinatesProvider;

  23. /**
  24.  * Event detector for eclipses from a single, infinitely-distant light source, occulted by a spherical central body.
  25.  * The shadow region is cylindrical, a model less accurate than a conical one but more computationally-performant.
  26.  * <p>
  27.  *     The so-called g function is negative in eclipse, positive otherwise.
  28.  * </p>
  29.  * @author Romain Serra
  30.  * @see EclipseDetector
  31.  * @since 12.1
  32.  */
  33. public class CylindricalShadowEclipseDetector extends AbstractDetector<CylindricalShadowEclipseDetector> {

  34.     /** Direction provider for the occulted light source i.e. the Sun (whose shadow is approximated as if the body was infinitely distant). */
  35.     private final PVCoordinatesProvider sun;

  36.     /** Radius of central, occulting body (approximated as spherical).
  37.      * Its center is assumed to be at the origin of the frame linked to the state. */
  38.     private final double occultingBodyRadius;

  39.     /**
  40.      * Constructor.
  41.      * @param sun light source provider (infinitely distant)
  42.      * @param occultingBodyRadius occulting body radius
  43.      * @param eventDetectionSettings detection settings
  44.      * @param handler event handler
  45.      * @since 12.2
  46.      */
  47.     public CylindricalShadowEclipseDetector(final PVCoordinatesProvider sun,
  48.                                             final double occultingBodyRadius,
  49.                                             final EventDetectionSettings eventDetectionSettings,
  50.                                             final EventHandler handler) {
  51.         super(eventDetectionSettings, handler);
  52.         this.sun = sun;
  53.         this.occultingBodyRadius = FastMath.abs(occultingBodyRadius);
  54.     }

  55.     /**
  56.      * Constructor with default detection settings.
  57.      * @param sun light source provider
  58.      * @param occultingBodyRadius occulting body radius
  59.      * @param handler event handler
  60.      */
  61.     public CylindricalShadowEclipseDetector(final PVCoordinatesProvider sun,
  62.                                             final double occultingBodyRadius, final EventHandler handler) {
  63.         this(sun, occultingBodyRadius, EventDetectionSettings.getDefaultEventDetectionSettings(), handler);
  64.     }

  65.     /**
  66.      * Getter for occulting body radius.
  67.      * @return radius
  68.      */
  69.     public double getOccultingBodyRadius() {
  70.         return occultingBodyRadius;
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public double g(final SpacecraftState s) {
  75.         final Vector3D sunDirection = sun.getPosition(s.getDate(), s.getFrame()).normalize();
  76.         final Vector3D position = s.getPosition();
  77.         final double dotProduct = position.dotProduct(sunDirection);
  78.         if (dotProduct >= 0.) {
  79.             return position.getNorm() / occultingBodyRadius;
  80.         } else {
  81.             final double distanceToCylinderAxis = (position.subtract(sunDirection.scalarMultiply(dotProduct))).getNorm();
  82.             return distanceToCylinderAxis / occultingBodyRadius - 1.;
  83.         }
  84.     }

  85.     /** {@inheritDoc} */
  86.     @Override
  87.     protected CylindricalShadowEclipseDetector create(final EventDetectionSettings detectionSettings,
  88.                                                       final EventHandler newHandler) {
  89.         return new CylindricalShadowEclipseDetector(sun, occultingBodyRadius, detectionSettings, newHandler);
  90.     }
  91. }