TimeStampedPVCoordinates.java

  1. /* Copyright 2002-2025 CS GROUP
  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.analysis.differentiation.Derivative;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.orekit.annotation.DefaultDataContext;
  22. import org.orekit.data.DataContext;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.TimeOffset;
  26. import org.orekit.time.TimeScale;
  27. import org.orekit.time.TimeStamped;

  28. /** {@link TimeStamped time-stamped} version of {@link PVCoordinates}.
  29.  * <p>Instances of this class are guaranteed to be immutable.</p>
  30.  * @author Luc Maisonobe
  31.  * @since 7.0
  32.  */
  33. public class TimeStampedPVCoordinates extends PVCoordinates implements TimeStamped {

  34.     /** The date. */
  35.     private final AbsoluteDate date;

  36.     /** Builds a TimeStampedPVCoordinates pair.
  37.      * @param date coordinates date
  38.      * @param position the position vector (m)
  39.      * @param velocity the velocity vector (m/s)
  40.      * @param acceleration the acceleration vector (m/s²)
  41.      */
  42.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  43.                                     final Vector3D position, final Vector3D velocity, final Vector3D acceleration) {
  44.         super(position, velocity, acceleration);
  45.         this.date = date;
  46.     }

  47.     /**
  48.      * Build from position and velocity. Acceleration is set to zero.
  49.      *
  50.      * @param date coordinates date
  51.      * @param position the position vector (m)
  52.      * @param velocity the velocity vector (m/s)
  53.      */
  54.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  55.                                     final Vector3D position,
  56.                                     final Vector3D velocity) {
  57.         this(date, position, velocity, Vector3D.ZERO);
  58.     }

  59.     /**
  60.      * Build from position velocity acceleration coordinates.
  61.      *
  62.      * @param date coordinates date
  63.      * @param pv position velocity, and acceleration coordinates, in meters and seconds.
  64.      */
  65.     public TimeStampedPVCoordinates(final AbsoluteDate date, final PVCoordinates pv) {
  66.         this(date, pv.getPosition(), pv.getVelocity(), pv.getAcceleration());
  67.     }

  68.     /** Multiplicative constructor
  69.      * <p>Build a TimeStampedPVCoordinates from another one and a scale factor.</p>
  70.      * <p>The TimeStampedPVCoordinates built will be a * pv</p>
  71.      * @param date date of the built coordinates
  72.      * @param a scale factor
  73.      * @param pv base (unscaled) PVCoordinates
  74.      */
  75.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  76.                                     final double a, final PVCoordinates pv) {
  77.         super(new Vector3D(a, pv.getPosition()),
  78.               new Vector3D(a, pv.getVelocity()),
  79.               new Vector3D(a, pv.getAcceleration()));
  80.         this.date = date;
  81.     }

  82.     /** Subtractive constructor
  83.      * <p>Build a relative TimeStampedPVCoordinates from a start and an end position.</p>
  84.      * <p>The TimeStampedPVCoordinates built will be end - start.</p>
  85.      * @param date date of the built coordinates
  86.      * @param start Starting PVCoordinates
  87.      * @param end ending PVCoordinates
  88.      */
  89.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  90.                                     final PVCoordinates start, final PVCoordinates end) {
  91.         super(end.getPosition().subtract(start.getPosition()),
  92.               end.getVelocity().subtract(start.getVelocity()),
  93.               end.getAcceleration().subtract(start.getAcceleration()));
  94.         this.date = date;
  95.     }

  96.     /** Linear constructor
  97.      * <p>Build a TimeStampedPVCoordinates from two other ones and corresponding scale factors.</p>
  98.      * <p>The TimeStampedPVCoordinates built will be a1 * u1 + a2 * u2</p>
  99.      * @param date date of the built coordinates
  100.      * @param a1 first scale factor
  101.      * @param pv1 first base (unscaled) PVCoordinates
  102.      * @param a2 second scale factor
  103.      * @param pv2 second base (unscaled) PVCoordinates
  104.      */
  105.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  106.                                     final double a1, final PVCoordinates pv1,
  107.                                     final double a2, final PVCoordinates pv2) {
  108.         super(new Vector3D(a1, pv1.getPosition(),     a2, pv2.getPosition()),
  109.               new Vector3D(a1, pv1.getVelocity(),     a2, pv2.getVelocity()),
  110.               new Vector3D(a1, pv1.getAcceleration(), a2, pv2.getAcceleration()));
  111.         this.date = date;
  112.     }

  113.     /** Linear constructor
  114.      * <p>Build a TimeStampedPVCoordinates from three other ones and corresponding scale factors.</p>
  115.      * <p>The TimeStampedPVCoordinates built will be a1 * u1 + a2 * u2 + a3 * u3</p>
  116.      * @param date date of the built coordinates
  117.      * @param a1 first scale factor
  118.      * @param pv1 first base (unscaled) PVCoordinates
  119.      * @param a2 second scale factor
  120.      * @param pv2 second base (unscaled) PVCoordinates
  121.      * @param a3 third scale factor
  122.      * @param pv3 third base (unscaled) PVCoordinates
  123.      */
  124.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  125.                                     final double a1, final PVCoordinates pv1,
  126.                                     final double a2, final PVCoordinates pv2,
  127.                                     final double a3, final PVCoordinates pv3) {
  128.         super(new Vector3D(a1, pv1.getPosition(),     a2, pv2.getPosition(),     a3, pv3.getPosition()),
  129.               new Vector3D(a1, pv1.getVelocity(),     a2, pv2.getVelocity(),     a3, pv3.getVelocity()),
  130.               new Vector3D(a1, pv1.getAcceleration(), a2, pv2.getAcceleration(), a3, pv3.getAcceleration()));
  131.         this.date = date;
  132.     }

  133.     /** Linear constructor
  134.      * <p>Build a TimeStampedPVCoordinates from four other ones and corresponding scale factors.</p>
  135.      * <p>The TimeStampedPVCoordinates built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4</p>
  136.      * @param date date of the built coordinates
  137.      * @param a1 first scale factor
  138.      * @param pv1 first base (unscaled) PVCoordinates
  139.      * @param a2 second scale factor
  140.      * @param pv2 second base (unscaled) PVCoordinates
  141.      * @param a3 third scale factor
  142.      * @param pv3 third base (unscaled) PVCoordinates
  143.      * @param a4 fourth scale factor
  144.      * @param pv4 fourth base (unscaled) PVCoordinates
  145.      */
  146.     public TimeStampedPVCoordinates(final AbsoluteDate date,
  147.                                     final double a1, final PVCoordinates pv1,
  148.                                     final double a2, final PVCoordinates pv2,
  149.                                     final double a3, final PVCoordinates pv3,
  150.                                     final double a4, final PVCoordinates pv4) {
  151.         super(new Vector3D(a1, pv1.getPosition(),     a2, pv2.getPosition(),     a3, pv3.getPosition(),     a4, pv4.getPosition()),
  152.               new Vector3D(a1, pv1.getVelocity(),     a2, pv2.getVelocity(),     a3, pv3.getVelocity(),     a4, pv4.getVelocity()),
  153.               new Vector3D(a1, pv1.getAcceleration(), a2, pv2.getAcceleration(), a3, pv3.getAcceleration(), a4, pv4.getAcceleration()));
  154.         this.date = date;
  155.     }

  156.     /** Builds a TimeStampedPVCoordinates triplet from  a {@link FieldVector3D}&lt;{@link Derivative}&gt;.
  157.      * <p>
  158.      * The vector components must have time as their only derivation parameter and
  159.      * have consistent derivation orders.
  160.      * </p>
  161.      * @param date date of the built coordinates
  162.      * @param p vector with time-derivatives embedded within the coordinates
  163.      * @param <U> type of the derivative
  164.      */
  165.     public <U extends Derivative<U>> TimeStampedPVCoordinates(final AbsoluteDate date, final FieldVector3D<U> p) {
  166.         super(p);
  167.         this.date = date;
  168.     }

  169.     /** {@inheritDoc} */
  170.     public AbsoluteDate getDate() {
  171.         return date;
  172.     }

  173.     /** Get a time-shifted state.
  174.      * <p>
  175.      * The state can be slightly shifted to close dates. This shift is based on
  176.      * a simple Taylor expansion. It is <em>not</em> intended as a replacement for
  177.      * proper orbit propagation (it is not even Keplerian!) but should be sufficient
  178.      * for either small time shifts or coarse accuracy.
  179.      * </p>
  180.      * @param dt time shift in seconds
  181.      * @return a new state, shifted with respect to the instance (which is immutable)
  182.      */
  183.     @Override
  184.     public TimeStampedPVCoordinates shiftedBy(final double dt) {
  185.         final PVCoordinates spv = super.shiftedBy(dt);
  186.         return new TimeStampedPVCoordinates(date.shiftedBy(dt),
  187.                                             spv.getPosition(), spv.getVelocity(), spv.getAcceleration());
  188.     }

  189.     /** Get a time-shifted state.
  190.      * <p>
  191.      * The state can be slightly shifted to close dates. This shift is based on
  192.      * a simple Taylor expansion. It is <em>not</em> intended as a replacement for
  193.      * proper orbit propagation (it is not even Keplerian!) but should be sufficient
  194.      * for either small time shifts or coarse accuracy.
  195.      * </p>
  196.      * @param dt time shift
  197.      * @return a new state, shifted with respect to the instance (which is immutable)
  198.      * @since 13.0
  199.      */
  200.     @Override
  201.     public TimeStampedPVCoordinates shiftedBy(final TimeOffset dt) {
  202.         final PVCoordinates spv = super.shiftedBy(dt);
  203.         return new TimeStampedPVCoordinates(date.shiftedBy(dt),
  204.                                             spv.getPosition(), spv.getVelocity(), spv.getAcceleration());
  205.     }

  206.     /** Create a local provider using simply Taylor expansion through {@link #shiftedBy(double)}.
  207.      * <p>
  208.      * The time evolution is based on a simple Taylor expansion. It is <em>not</em> intended as a
  209.      * replacement for proper orbit propagation (it is not even Keplerian!) but should be sufficient
  210.      * for either small time shifts or coarse accuracy.
  211.      * </p>
  212.      * @param instanceFrame frame in which the instance is defined
  213.      * @return provider based on Taylor expansion, for small time shifts around instance date
  214.      */
  215.     public PVCoordinatesProvider toTaylorProvider(final Frame instanceFrame) {
  216.         return new ShiftingPVCoordinatesProvider(this, instanceFrame);
  217.     }

  218.     /** Return a string representation of this date, position, velocity, and acceleration.
  219.      *
  220.      * <p>This method uses the {@link DataContext#getDefault() default data context}.
  221.      *
  222.      * @return string representation of this.
  223.      */
  224.     @Override
  225.     @DefaultDataContext
  226.     public String toString() {
  227.         return toString(DataContext.getDefault().getTimeScales().getUTC());
  228.     }

  229.     /**
  230.      * Return a string representation of this date, position, velocity, and acceleration.
  231.      *
  232.      * @param utc time scale used to print the date.
  233.      * @return string representation of this.
  234.      */
  235.     public String toString(final TimeScale utc) {
  236.         final String comma = ", ";
  237.         return new StringBuilder().append('{').
  238.                                   append(date.toString(utc)).append(", P(").
  239.                                   append(getPosition().getX()).append(comma).
  240.                                   append(getPosition().getY()).append(comma).
  241.                                   append(getPosition().getZ()).append("), V(").
  242.                                   append(getVelocity().getX()).append(comma).
  243.                                   append(getVelocity().getY()).append(comma).
  244.                                   append(getVelocity().getZ()).append("), A(").
  245.                                   append(getAcceleration().getX()).append(comma).
  246.                                   append(getAcceleration().getY()).append(comma).
  247.                                   append(getAcceleration().getZ()).append(")}").toString();
  248.     }

  249. }