FieldCylindricalShadowEclipseDetector.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.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.util.FastMath;
  21. import org.orekit.propagation.FieldSpacecraftState;
  22. import org.orekit.propagation.events.handlers.FieldEventHandler;
  23. import org.orekit.utils.ExtendedPositionProvider;

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

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

  40.     /** Radius of central, occulting body (approximated as spherical).
  41.      * Its center is assumed to be at the origin of the frame linked to the state. */
  42.     private final T occultingBodyRadius;

  43.     /**
  44.      * Constructor.
  45.      * @param sun light source provider (infinitely distant)
  46.      * @param occultingBodyRadius occulting body radius
  47.      * @param eventDetectionSettings detection settings
  48.      * @param handler event handler
  49.      * @since 12.2
  50.      */
  51.     public FieldCylindricalShadowEclipseDetector(final ExtendedPositionProvider sun,
  52.                                                  final T occultingBodyRadius,
  53.                                                  final FieldEventDetectionSettings<T> eventDetectionSettings,
  54.                                                  final FieldEventHandler<T> handler) {
  55.         super(eventDetectionSettings, handler);
  56.         this.sun = sun;
  57.         this.occultingBodyRadius = FastMath.abs(occultingBodyRadius);
  58.     }

  59.     /**
  60.      * Constructor with default detection settings.
  61.      * @param sun light source provider
  62.      * @param occultingBodyRadius occulting body radius
  63.      * @param handler event handler
  64.      */
  65.     public FieldCylindricalShadowEclipseDetector(final ExtendedPositionProvider sun,
  66.                                                  final T occultingBodyRadius, final FieldEventHandler<T> handler) {
  67.         this(sun, occultingBodyRadius, new FieldEventDetectionSettings<>(occultingBodyRadius.getField(),
  68.             EventDetectionSettings.getDefaultEventDetectionSettings()), handler);
  69.     }

  70.     /**
  71.      * Getter for occulting body radius.
  72.      * @return radius
  73.      */
  74.     public T getOccultingBodyRadius() {
  75.         return occultingBodyRadius;
  76.     }

  77.     /** {@inheritDoc} */
  78.     @Override
  79.     public T g(final FieldSpacecraftState<T> s) {
  80.         final FieldVector3D<T> sunDirection = sun.getPosition(s.getDate(), s.getFrame()).normalize();
  81.         final FieldVector3D<T> position = s.getPosition();
  82.         final T dotProduct = position.dotProduct(sunDirection);
  83.         if (dotProduct.getReal() >= 0.) {
  84.             return position.getNorm().divide(occultingBodyRadius);
  85.         } else {
  86.             final T distanceToCylinderAxis = (position.subtract(sunDirection.scalarMultiply(dotProduct))).getNorm();
  87.             return distanceToCylinderAxis.divide(occultingBodyRadius).subtract(1.);
  88.         }
  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     protected FieldCylindricalShadowEclipseDetector<T> create(final FieldEventDetectionSettings<T> detectionSettings,
  93.                                                               final FieldEventHandler<T> newHandler) {
  94.         return new FieldCylindricalShadowEclipseDetector<>(sun, occultingBodyRadius, detectionSettings, newHandler);
  95.     }
  96. }