FieldCylindricalShadowEclipseDetector.java

  1. /* Copyright 2022-2024 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.1
  34.  */
  35. public class FieldCylindricalShadowEclipseDetector<T extends CalculusFieldElement<T>>
  36.     extends FieldAbstractDetector<FieldCylindricalShadowEclipseDetector<T>, T> {

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

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

  42.     /**
  43.      * Constructor.
  44.      * @param sun light source provider (infinitely distant)
  45.      * @param occultingBodyRadius occulting body radius
  46.      * @param maxCheck maximum check for event detection
  47.      * @param threshold threshold for event detection
  48.      * @param maxIter maximum iteration for event detection
  49.      * @param handler event handler
  50.      */
  51.     public FieldCylindricalShadowEclipseDetector(final ExtendedPositionProvider sun,
  52.                                                  final T occultingBodyRadius,
  53.                                                  final FieldAdaptableInterval<T> maxCheck, final T threshold,
  54.                                                  final int maxIter, final FieldEventHandler<T> handler) {
  55.         super(maxCheck, threshold, maxIter, 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, FieldAdaptableInterval.of(DEFAULT_MAXCHECK), occultingBodyRadius.getField().getZero().newInstance(DEFAULT_THRESHOLD),
  68.             DEFAULT_MAX_ITER, 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 FieldAdaptableInterval<T> newMaxCheck, final T newThreshold,
  93.                                                               final int newMaxIter, final FieldEventHandler<T> newHandler) {
  94.         return new FieldCylindricalShadowEclipseDetector<>(sun, occultingBodyRadius, newMaxCheck, newThreshold, newMaxIter, newHandler);
  95.     }
  96. }