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

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

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

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

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

  57.     /** Get the position-velocity-acceleration in the selected frame.
  58.      * @param date current date
  59.      * @param frame the frame where to define the position
  60.      * @param <T> field type
  61.      * @return position-velocity-acceleration vector
  62.      */
  63.     default <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date,
  64.                                                                                                   final Frame frame) {
  65.         final Field<T> field = date.getField();
  66.         final FieldUnivariateDerivative2Field<T> fud2Field = FieldUnivariateDerivative2Field.getUnivariateDerivative2Field(field);
  67.         final T fieldShift = date.durationFrom(date.toAbsoluteDate());
  68.         final FieldUnivariateDerivative2<T> fud2Shift = new FieldUnivariateDerivative2<>(fieldShift, field.getOne(),
  69.             field.getZero());
  70.         final FieldAbsoluteDate<FieldUnivariateDerivative2<T>> fud2Date = new FieldAbsoluteDate<>(fud2Field,
  71.             date.toAbsoluteDate()).shiftedBy(fud2Shift);
  72.         final FieldVector3D<FieldUnivariateDerivative2<T>> fud2Position = getPosition(fud2Date, frame);
  73.         final FieldVector3D<T> position = new FieldVector3D<>(fud2Position.getX().getValue(), fud2Position.getY().getValue(),
  74.             fud2Position.getZ().getValue());
  75.         final FieldVector3D<T> velocity = new FieldVector3D<>(fud2Position.getX().getFirstDerivative(), fud2Position.getY().getFirstDerivative(),
  76.             fud2Position.getZ().getFirstDerivative());
  77.         final FieldVector3D<T> acceleration = new FieldVector3D<>(fud2Position.getX().getSecondDerivative(), fud2Position.getY().getSecondDerivative(),
  78.             fud2Position.getZ().getSecondDerivative());
  79.         return new TimeStampedFieldPVCoordinates<>(date, position, velocity, acceleration);
  80.     }

  81.     /** Convert to a {@link FieldPVCoordinatesProvider} with a specific type.
  82.      * @param <T> the type of the field elements
  83.      * @param field field for the argument and value
  84.      * @return converted function
  85.      */
  86.     default <T extends CalculusFieldElement<T>> FieldPVCoordinatesProvider<T> toFieldPVCoordinatesProvider(Field<T> field) {
  87.         return new FieldPVCoordinatesProvider<T>() {

  88.             @Override
  89.             public FieldVector3D<T> getPosition(final FieldAbsoluteDate<T> date, final Frame frame) {
  90.                 return ExtendedPositionProvider.this.getPosition(date, frame);
  91.             }

  92.             @Override
  93.             public TimeStampedFieldPVCoordinates<T> getPVCoordinates(final FieldAbsoluteDate<T> date,
  94.                                                                      final Frame frame) {
  95.                 return ExtendedPositionProvider.this.getPVCoordinates(date, frame);
  96.             }
  97.         };
  98.     }
  99. }