ExtendedPositionProvider.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.utils;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.analysis.differentiation.FieldUnivariateDerivative2;
  21. import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
  22. import org.hipparchus.analysis.differentiation.UnivariateDerivative2Field;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;

  28. /**
  29.  * Interface for position providers (including for Field).
  30.  * Emulates position (and derivatives) vector as a function of time.
  31.  * @author Romain Serra
  32.  * @since 12.1
  33.  */
  34. public interface ExtendedPositionProvider extends PVCoordinatesProvider {

  35.     /** Get the position in the selected frame.
  36.      * @param date current date
  37.      * @param frame the frame where to define the position
  38.      * @param <T> field type
  39.      * @return position
  40.      */
  41.     <T extends CalculusFieldElement<T>> FieldVector3D<T> getPosition(FieldAbsoluteDate<T> date, Frame frame);

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     default TimeStampedPVCoordinates getPVCoordinates(final AbsoluteDate date, final Frame frame) {
  45.         final UnivariateDerivative2Field ud2Field = UnivariateDerivative2Field.getInstance();
  46.         final UnivariateDerivative2 ud2Shift = new UnivariateDerivative2(0., 1., 0.);
  47.         final FieldAbsoluteDate<UnivariateDerivative2> fieldDate = new FieldAbsoluteDate<>(ud2Field, date).shiftedBy(ud2Shift);
  48.         final FieldVector3D<UnivariateDerivative2> ud2Position = getPosition(fieldDate, frame);
  49.         final Vector3D position = ud2Position.toVector3D();
  50.         final Vector3D velocity = new Vector3D(ud2Position.getX().getFirstDerivative(), ud2Position.getY().getFirstDerivative(),
  51.             ud2Position.getZ().getFirstDerivative());
  52.         final Vector3D acceleration = new Vector3D(ud2Position.getX().getSecondDerivative(), ud2Position.getY().getSecondDerivative(),
  53.                 ud2Position.getZ().getSecondDerivative());
  54.         return new TimeStampedPVCoordinates(date, new PVCoordinates(position, velocity, acceleration));
  55.     }

  56.     /** Get the position-velocity-acceleration in the selected frame.
  57.      * @param date current date
  58.      * @param frame the frame where to define the position
  59.      * @param <T> field type
  60.      * @return position-velocity-acceleration vector
  61.      */
  62.     default <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date,
  63.                                                                                                   final Frame frame) {
  64.         final FieldAbsoluteDate<FieldUnivariateDerivative2<T>> fud2Date = date.toFUD2Field();
  65.         final FieldVector3D<FieldUnivariateDerivative2<T>> fud2Position = getPosition(fud2Date, frame);
  66.         final FieldVector3D<T> position = new FieldVector3D<>(fud2Position.getX().getValue(), fud2Position.getY().getValue(),
  67.             fud2Position.getZ().getValue());
  68.         final FieldVector3D<T> velocity = new FieldVector3D<>(fud2Position.getX().getFirstDerivative(), fud2Position.getY().getFirstDerivative(),
  69.             fud2Position.getZ().getFirstDerivative());
  70.         final FieldVector3D<T> acceleration = new FieldVector3D<>(fud2Position.getX().getSecondDerivative(), fud2Position.getY().getSecondDerivative(),
  71.             fud2Position.getZ().getSecondDerivative());
  72.         return new TimeStampedFieldPVCoordinates<>(date, position, velocity, acceleration);
  73.     }

  74.     /** Convert to a {@link FieldPVCoordinatesProvider} with a specific type.
  75.      * @param <T> the type of the field elements
  76.      * @param field field for the argument and value
  77.      * @return converted function
  78.      */
  79.     default <T extends CalculusFieldElement<T>> FieldPVCoordinatesProvider<T> toFieldPVCoordinatesProvider(Field<T> field) {
  80.         return new FieldPVCoordinatesProvider<T>() {

  81.             @Override
  82.             public FieldVector3D<T> getPosition(final FieldAbsoluteDate<T> date, final Frame frame) {
  83.                 return ExtendedPositionProvider.this.getPosition(date, frame);
  84.             }

  85.             @Override
  86.             public TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date,
  87.                                                                      final Frame frame) {
  88.                 return ExtendedPositionProvider.this.getPVCoordinates(date, frame);
  89.             }
  90.         };
  91.     }

  92.     /**
  93.      * Method to convert as {@link ExtendedPVCoordinatesProvider}.
  94.      * @return converted object
  95.      * @since 13.0
  96.      * @deprecated since 13.0. Only there to help transition out.
  97.      */
  98.     @Deprecated
  99.     default ExtendedPVCoordinatesProvider toExtendedPVCoordinatesProvider() {
  100.         return ExtendedPositionProvider.this::getPVCoordinates;
  101.     }
  102. }