CartesianOrbit.java

  1. /* Copyright 2002-2023 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.orbits;

  18. import java.io.Serializable;

  19. import org.hipparchus.analysis.differentiation.UnivariateDerivative2;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Rotation;
  22. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.linear.MatrixUtils;
  25. import org.hipparchus.util.FastMath;
  26. import org.hipparchus.util.SinCos;
  27. import org.orekit.annotation.DefaultDataContext;
  28. import org.orekit.data.DataContext;
  29. import org.orekit.frames.Frame;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.utils.FieldPVCoordinates;
  32. import org.orekit.utils.PVCoordinates;
  33. import org.orekit.utils.TimeStampedPVCoordinates;


  34. /** This class holds Cartesian orbital parameters.

  35.  * <p>
  36.  * The parameters used internally are the Cartesian coordinates:
  37.  *   <ul>
  38.  *     <li>x</li>
  39.  *     <li>y</li>
  40.  *     <li>z</li>
  41.  *     <li>xDot</li>
  42.  *     <li>yDot</li>
  43.  *     <li>zDot</li>
  44.  *   </ul>
  45.  * contained in {@link PVCoordinates}.
  46.  *

  47.  * <p>
  48.  * Note that the implementation of this class delegates all non-Cartesian related
  49.  * computations ({@link #getA()}, {@link #getEquinoctialEx()}, ...) to an underlying
  50.  * instance of the {@link EquinoctialOrbit} class. This implies that using this class
  51.  * only for analytical computations which are always based on non-Cartesian
  52.  * parameters is perfectly possible but somewhat sub-optimal.
  53.  * </p>
  54.  * <p>
  55.  * The instance <code>CartesianOrbit</code> is guaranteed to be immutable.
  56.  * </p>
  57.  * @see    Orbit
  58.  * @see    KeplerianOrbit
  59.  * @see    CircularOrbit
  60.  * @see    EquinoctialOrbit
  61.  * @author Luc Maisonobe
  62.  * @author Guylaine Prat
  63.  * @author Fabien Maussion
  64.  * @author V&eacute;ronique Pommier-Maurussane
  65.  * @author Andrew Goetz
  66.  */
  67. public class CartesianOrbit extends Orbit {

  68.     /** Serializable UID. */
  69.     private static final long serialVersionUID = 20170414L;

  70.     /** 6x6 identity matrix. */
  71.     private static final double[][] SIX_BY_SIX_IDENTITY = MatrixUtils.createRealIdentityMatrix(6).getData();

  72.     /** Indicator for non-Keplerian derivatives. */
  73.     private final transient boolean hasNonKeplerianAcceleration;

  74.     /** Underlying equinoctial orbit to which high-level methods are delegated. */
  75.     private transient EquinoctialOrbit equinoctial;

  76.     /** Constructor from Cartesian parameters.
  77.      *
  78.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  79.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  80.      * use {@code mu} and the position to compute the acceleration, including
  81.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  82.      *
  83.      * @param pvaCoordinates the position, velocity and acceleration of the satellite.
  84.      * @param frame the frame in which the {@link PVCoordinates} are defined
  85.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  86.      * @param mu central attraction coefficient (m³/s²)
  87.      * @exception IllegalArgumentException if frame is not a {@link
  88.      * Frame#isPseudoInertial pseudo-inertial frame}
  89.      */
  90.     public CartesianOrbit(final TimeStampedPVCoordinates pvaCoordinates,
  91.                           final Frame frame, final double mu)
  92.         throws IllegalArgumentException {
  93.         super(pvaCoordinates, frame, mu);
  94.         hasNonKeplerianAcceleration = hasNonKeplerianAcceleration(pvaCoordinates, mu);
  95.         equinoctial = null;
  96.     }

  97.     /** Constructor from Cartesian parameters.
  98.      *
  99.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  100.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  101.      * use {@code mu} and the position to compute the acceleration, including
  102.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  103.      *
  104.      * @param pvaCoordinates the position and velocity of the satellite.
  105.      * @param frame the frame in which the {@link PVCoordinates} are defined
  106.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  107.      * @param date date of the orbital parameters
  108.      * @param mu central attraction coefficient (m³/s²)
  109.      * @exception IllegalArgumentException if frame is not a {@link
  110.      * Frame#isPseudoInertial pseudo-inertial frame}
  111.      */
  112.     public CartesianOrbit(final PVCoordinates pvaCoordinates, final Frame frame,
  113.                           final AbsoluteDate date, final double mu)
  114.         throws IllegalArgumentException {
  115.         this(new TimeStampedPVCoordinates(date, pvaCoordinates), frame, mu);
  116.     }

  117.     /** Constructor from any kind of orbital parameters.
  118.      * @param op orbital parameters to copy
  119.      */
  120.     public CartesianOrbit(final Orbit op) {
  121.         super(op.getPVCoordinates(), op.getFrame(), op.getMu());
  122.         hasNonKeplerianAcceleration = op.hasDerivatives();
  123.         if (op instanceof EquinoctialOrbit) {
  124.             equinoctial = (EquinoctialOrbit) op;
  125.         } else if (op instanceof CartesianOrbit) {
  126.             equinoctial = ((CartesianOrbit) op).equinoctial;
  127.         } else {
  128.             equinoctial = null;
  129.         }
  130.     }

  131.     /** {@inheritDoc} */
  132.     public OrbitType getType() {
  133.         return OrbitType.CARTESIAN;
  134.     }

  135.     /** Lazy evaluation of equinoctial parameters. */
  136.     private void initEquinoctial() {
  137.         if (equinoctial == null) {
  138.             if (hasDerivatives()) {
  139.                 // getPVCoordinates includes accelerations that will be interpreted as derivatives
  140.                 equinoctial = new EquinoctialOrbit(getPVCoordinates(), getFrame(), getDate(), getMu());
  141.             } else {
  142.                 // get rid of Keplerian acceleration so we don't assume
  143.                 // we have derivatives when in fact we don't have them
  144.                 equinoctial = new EquinoctialOrbit(new PVCoordinates(getPosition(),
  145.                                                                      getPVCoordinates().getVelocity()),
  146.                                                    getFrame(), getDate(), getMu());
  147.             }
  148.         }
  149.     }

  150.     /** Get the position/velocity with derivatives.
  151.      * @return position/velocity with derivatives
  152.      * @since 10.2
  153.      */
  154.     private FieldPVCoordinates<UnivariateDerivative2> getPVDerivatives() {
  155.         // PVA coordinates
  156.         final PVCoordinates pva = getPVCoordinates();
  157.         final Vector3D      p   = pva.getPosition();
  158.         final Vector3D      v   = pva.getVelocity();
  159.         final Vector3D      a   = pva.getAcceleration();
  160.         // Field coordinates
  161.         final FieldVector3D<UnivariateDerivative2> pG = new FieldVector3D<>(new UnivariateDerivative2(p.getX(), v.getX(), a.getX()),
  162.                                                                new UnivariateDerivative2(p.getY(), v.getY(), a.getY()),
  163.                                                                new UnivariateDerivative2(p.getZ(), v.getZ(), a.getZ()));
  164.         final FieldVector3D<UnivariateDerivative2> vG = new FieldVector3D<>(new UnivariateDerivative2(v.getX(), a.getX(), 0.0),
  165.                                                                new UnivariateDerivative2(v.getY(), a.getY(), 0.0),
  166.                                                                new UnivariateDerivative2(v.getZ(), a.getZ(), 0.0));
  167.         return new FieldPVCoordinates<>(pG, vG);
  168.     }

  169.     /** {@inheritDoc} */
  170.     public double getA() {
  171.         final double r  = getPosition().getNorm();
  172.         final double V2 = getPVCoordinates().getVelocity().getNormSq();
  173.         return r / (2 - r * V2 / getMu());
  174.     }

  175.     /** {@inheritDoc} */
  176.     public double getADot() {
  177.         if (hasDerivatives()) {
  178.             final FieldPVCoordinates<UnivariateDerivative2> pv = getPVDerivatives();
  179.             final UnivariateDerivative2 r  = pv.getPosition().getNorm();
  180.             final UnivariateDerivative2 V2 = pv.getVelocity().getNormSq();
  181.             final UnivariateDerivative2 a  = r.divide(r.multiply(V2).divide(getMu()).subtract(2).negate());
  182.             return a.getDerivative(1);
  183.         } else {
  184.             return Double.NaN;
  185.         }
  186.     }

  187.     /** {@inheritDoc} */
  188.     public double getE() {
  189.         final double muA = getMu() * getA();
  190.         if (isElliptical()) {
  191.             // elliptic or circular orbit
  192.             final Vector3D pvP   = getPosition();
  193.             final Vector3D pvV   = getPVCoordinates().getVelocity();
  194.             final double rV2OnMu = pvP.getNorm() * pvV.getNormSq() / getMu();
  195.             final double eSE     = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(muA);
  196.             final double eCE     = rV2OnMu - 1;
  197.             return FastMath.sqrt(eCE * eCE + eSE * eSE);
  198.         } else {
  199.             // hyperbolic orbit
  200.             final Vector3D pvM = getPVCoordinates().getMomentum();
  201.             return FastMath.sqrt(1 - pvM.getNormSq() / muA);
  202.         }
  203.     }

  204.     /** {@inheritDoc} */
  205.     public double getEDot() {
  206.         if (hasDerivatives()) {
  207.             final FieldPVCoordinates<UnivariateDerivative2> pv = getPVDerivatives();
  208.             final FieldVector3D<UnivariateDerivative2> pvP   = pv.getPosition();
  209.             final FieldVector3D<UnivariateDerivative2> pvV   = pv.getVelocity();
  210.             final UnivariateDerivative2 r       = pvP.getNorm();
  211.             final UnivariateDerivative2 V2      = pvV.getNormSq();
  212.             final UnivariateDerivative2 rV2OnMu = r.multiply(V2).divide(getMu());
  213.             final UnivariateDerivative2 a       = r.divide(rV2OnMu.negate().add(2));
  214.             final UnivariateDerivative2 eSE     = FieldVector3D.dotProduct(pvP, pvV).divide(a.multiply(getMu()).sqrt());
  215.             final UnivariateDerivative2 eCE     = rV2OnMu.subtract(1);
  216.             final UnivariateDerivative2 e       = eCE.multiply(eCE).add(eSE.multiply(eSE)).sqrt();
  217.             return e.getDerivative(1);
  218.         } else {
  219.             return Double.NaN;
  220.         }
  221.     }

  222.     /** {@inheritDoc} */
  223.     public double getI() {
  224.         return Vector3D.angle(Vector3D.PLUS_K, getPVCoordinates().getMomentum());
  225.     }

  226.     /** {@inheritDoc} */
  227.     public double getIDot() {
  228.         if (hasDerivatives()) {
  229.             final FieldPVCoordinates<UnivariateDerivative2> pv = getPVDerivatives();
  230.             final FieldVector3D<UnivariateDerivative2> momentum =
  231.                             FieldVector3D.crossProduct(pv.getPosition(), pv.getVelocity());
  232.             final UnivariateDerivative2 i = FieldVector3D.angle(Vector3D.PLUS_K, momentum);
  233.             return i.getDerivative(1);
  234.         } else {
  235.             return Double.NaN;
  236.         }
  237.     }

  238.     /** {@inheritDoc} */
  239.     public double getEquinoctialEx() {
  240.         initEquinoctial();
  241.         return equinoctial.getEquinoctialEx();
  242.     }

  243.     /** {@inheritDoc} */
  244.     public double getEquinoctialExDot() {
  245.         initEquinoctial();
  246.         return equinoctial.getEquinoctialExDot();
  247.     }

  248.     /** {@inheritDoc} */
  249.     public double getEquinoctialEy() {
  250.         initEquinoctial();
  251.         return equinoctial.getEquinoctialEy();
  252.     }

  253.     /** {@inheritDoc} */
  254.     public double getEquinoctialEyDot() {
  255.         initEquinoctial();
  256.         return equinoctial.getEquinoctialEyDot();
  257.     }

  258.     /** {@inheritDoc} */
  259.     public double getHx() {
  260.         final Vector3D w = getPVCoordinates().getMomentum().normalize();
  261.         // Check for equatorial retrograde orbit
  262.         if ((w.getX() * w.getX() + w.getY() * w.getY()) == 0 && w.getZ() < 0) {
  263.             return Double.NaN;
  264.         }
  265.         return -w.getY() / (1 + w.getZ());
  266.     }

  267.     /** {@inheritDoc} */
  268.     public double getHxDot() {
  269.         if (hasDerivatives()) {
  270.             final FieldPVCoordinates<UnivariateDerivative2> pv = getPVDerivatives();
  271.             final FieldVector3D<UnivariateDerivative2> w =
  272.                             FieldVector3D.crossProduct(pv.getPosition(), pv.getVelocity()).normalize();
  273.             // Check for equatorial retrograde orbit
  274.             final double x = w.getX().getValue();
  275.             final double y = w.getY().getValue();
  276.             final double z = w.getZ().getValue();
  277.             if ((x * x + y * y) == 0 && z < 0) {
  278.                 return Double.NaN;
  279.             }
  280.             final UnivariateDerivative2 hx = w.getY().negate().divide(w.getZ().add(1));
  281.             return hx.getDerivative(1);
  282.         } else {
  283.             return Double.NaN;
  284.         }
  285.     }

  286.     /** {@inheritDoc} */
  287.     public double getHy() {
  288.         final Vector3D w = getPVCoordinates().getMomentum().normalize();
  289.         // Check for equatorial retrograde orbit
  290.         if ((w.getX() * w.getX() + w.getY() * w.getY()) == 0 && w.getZ() < 0) {
  291.             return Double.NaN;
  292.         }
  293.         return  w.getX() / (1 + w.getZ());
  294.     }

  295.     /** {@inheritDoc} */
  296.     public double getHyDot() {
  297.         if (hasDerivatives()) {
  298.             final FieldPVCoordinates<UnivariateDerivative2> pv = getPVDerivatives();
  299.             final FieldVector3D<UnivariateDerivative2> w =
  300.                             FieldVector3D.crossProduct(pv.getPosition(), pv.getVelocity()).normalize();
  301.             // Check for equatorial retrograde orbit
  302.             final double x = w.getX().getValue();
  303.             final double y = w.getY().getValue();
  304.             final double z = w.getZ().getValue();
  305.             if ((x * x + y * y) == 0 && z < 0) {
  306.                 return Double.NaN;
  307.             }
  308.             final UnivariateDerivative2 hy = w.getX().divide(w.getZ().add(1));
  309.             return hy.getDerivative(1);
  310.         } else {
  311.             return Double.NaN;
  312.         }
  313.     }

  314.     /** {@inheritDoc} */
  315.     public double getLv() {
  316.         initEquinoctial();
  317.         return equinoctial.getLv();
  318.     }

  319.     /** {@inheritDoc} */
  320.     public double getLvDot() {
  321.         initEquinoctial();
  322.         return equinoctial.getLvDot();
  323.     }

  324.     /** {@inheritDoc} */
  325.     public double getLE() {
  326.         initEquinoctial();
  327.         return equinoctial.getLE();
  328.     }

  329.     /** {@inheritDoc} */
  330.     public double getLEDot() {
  331.         initEquinoctial();
  332.         return equinoctial.getLEDot();
  333.     }

  334.     /** {@inheritDoc} */
  335.     public double getLM() {
  336.         initEquinoctial();
  337.         return equinoctial.getLM();
  338.     }

  339.     /** {@inheritDoc} */
  340.     public double getLMDot() {
  341.         initEquinoctial();
  342.         return equinoctial.getLMDot();
  343.     }

  344.     /** {@inheritDoc} */
  345.     public boolean hasDerivatives() {
  346.         return hasNonKeplerianAcceleration;
  347.     }

  348.     /** {@inheritDoc} */
  349.     protected Vector3D initPosition() {
  350.         // nothing to do here, as the canonical elements are already the Cartesian ones
  351.         return getPVCoordinates().getPosition();
  352.     }

  353.     /** {@inheritDoc} */
  354.     protected TimeStampedPVCoordinates initPVCoordinates() {
  355.         // nothing to do here, as the canonical elements are already the Cartesian ones
  356.         return getPVCoordinates();
  357.     }

  358.     /** {@inheritDoc} */
  359.     public CartesianOrbit shiftedBy(final double dt) {
  360.         final PVCoordinates shiftedPV = isElliptical() ? shiftPVElliptic(dt) : shiftPVHyperbolic(dt);
  361.         return new CartesianOrbit(shiftedPV, getFrame(), getDate().shiftedBy(dt), getMu());
  362.     }

  363.     /** Compute shifted position and velocity in elliptic case.
  364.      * @param dt time shift
  365.      * @return shifted position and velocity
  366.      */
  367.     private PVCoordinates shiftPVElliptic(final double dt) {

  368.         // preliminary computation
  369.         final PVCoordinates pv = getPVCoordinates();
  370.         final Vector3D pvP     = pv.getPosition();
  371.         final Vector3D pvV     = pv.getVelocity();
  372.         final Vector3D pvM     = pv.getMomentum();
  373.         final double r2        = pvP.getNormSq();
  374.         final double r         = FastMath.sqrt(r2);
  375.         final double rV2OnMu   = r * pvV.getNormSq() / getMu();
  376.         final double a         = r / (2 - rV2OnMu);
  377.         final double muA       = getMu() * a;

  378.         // compute mean anomaly
  379.         final double eSE    = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(muA);
  380.         final double eCE    = rV2OnMu - 1;
  381.         final double E0     = FastMath.atan2(eSE, eCE);
  382.         final double M0     = E0 - eSE;

  383.         final double e         = FastMath.sqrt(eCE * eCE + eSE * eSE);
  384.         final double sqrt      = FastMath.sqrt((1 + e) / (1 - e));

  385.         // find canonical 2D frame with p pointing to perigee
  386.         final double v0     = 2 * FastMath.atan(sqrt * FastMath.tan(E0 / 2));
  387.         final Vector3D p    = new Rotation(pvM, v0, RotationConvention.FRAME_TRANSFORM).applyTo(pvP).normalize();
  388.         final Vector3D q    = Vector3D.crossProduct(pvM, p).normalize();

  389.         // compute shifted eccentric anomaly
  390.         final double M1     = M0 + getKeplerianMeanMotion() * dt;
  391.         final double E1     = KeplerianAnomalyUtility.ellipticMeanToEccentric(e, M1);

  392.         // compute shifted in-plane Cartesian coordinates
  393.         final SinCos scE    = FastMath.sinCos(E1);
  394.         final double cE     = scE.cos();
  395.         final double sE     = scE.sin();
  396.         final double sE2m1  = FastMath.sqrt((1 - e) * (1 + e));

  397.         // coordinates of position and velocity in the orbital plane
  398.         final double x      = a * (cE - e);
  399.         final double y      = a * sE2m1 * sE;
  400.         final double factor = FastMath.sqrt(getMu() / a) / (1 - e * cE);
  401.         final double xDot   = -factor * sE;
  402.         final double yDot   =  factor * sE2m1 * cE;

  403.         final Vector3D shiftedP = new Vector3D(x, p, y, q);
  404.         final Vector3D shiftedV = new Vector3D(xDot, p, yDot, q);
  405.         if (hasNonKeplerianAcceleration) {

  406.             // extract non-Keplerian part of the initial acceleration
  407.             final Vector3D nonKeplerianAcceleration = new Vector3D(1, getPVCoordinates().getAcceleration(),
  408.                                                                    getMu() / (r2 * r), pvP);

  409.             // add the quadratic motion due to the non-Keplerian acceleration to the Keplerian motion
  410.             final Vector3D fixedP   = new Vector3D(1, shiftedP,
  411.                                                    0.5 * dt * dt, nonKeplerianAcceleration);
  412.             final double   fixedR2 = fixedP.getNormSq();
  413.             final double   fixedR  = FastMath.sqrt(fixedR2);
  414.             final Vector3D fixedV  = new Vector3D(1, shiftedV,
  415.                                                   dt, nonKeplerianAcceleration);
  416.             final Vector3D fixedA  = new Vector3D(-getMu() / (fixedR2 * fixedR), shiftedP,
  417.                                                   1, nonKeplerianAcceleration);

  418.             return new PVCoordinates(fixedP, fixedV, fixedA);

  419.         } else {
  420.             // don't include acceleration,
  421.             // so the shifted orbit is not considered to have derivatives
  422.             return new PVCoordinates(shiftedP, shiftedV);
  423.         }

  424.     }

  425.     /** Compute shifted position and velocity in hyperbolic case.
  426.      * @param dt time shift
  427.      * @return shifted position and velocity
  428.      */
  429.     private PVCoordinates shiftPVHyperbolic(final double dt) {

  430.         final PVCoordinates pv = getPVCoordinates();
  431.         final Vector3D pvP   = pv.getPosition();
  432.         final Vector3D pvV   = pv.getVelocity();
  433.         final Vector3D pvM   = pv.getMomentum();
  434.         final double r2      = pvP.getNormSq();
  435.         final double r       = FastMath.sqrt(r2);
  436.         final double rV2OnMu = r * pvV.getNormSq() / getMu();
  437.         final double a       = getA();
  438.         final double muA     = getMu() * a;
  439.         final double e       = FastMath.sqrt(1 - Vector3D.dotProduct(pvM, pvM) / muA);
  440.         final double sqrt    = FastMath.sqrt((e + 1) / (e - 1));

  441.         // compute mean anomaly
  442.         final double eSH     = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(-muA);
  443.         final double eCH     = rV2OnMu - 1;
  444.         final double H0      = FastMath.log((eCH + eSH) / (eCH - eSH)) / 2;
  445.         final double M0      = e * FastMath.sinh(H0) - H0;

  446.         // find canonical 2D frame with p pointing to perigee
  447.         final double v0      = 2 * FastMath.atan(sqrt * FastMath.tanh(H0 / 2));
  448.         final Vector3D p     = new Rotation(pvM, v0, RotationConvention.FRAME_TRANSFORM).applyTo(pvP).normalize();
  449.         final Vector3D q     = Vector3D.crossProduct(pvM, p).normalize();

  450.         // compute shifted eccentric anomaly
  451.         final double M1      = M0 + getKeplerianMeanMotion() * dt;
  452.         final double H1      = KeplerianAnomalyUtility.hyperbolicMeanToEccentric(e, M1);

  453.         // compute shifted in-plane Cartesian coordinates
  454.         final double cH     = FastMath.cosh(H1);
  455.         final double sH     = FastMath.sinh(H1);
  456.         final double sE2m1  = FastMath.sqrt((e - 1) * (e + 1));

  457.         // coordinates of position and velocity in the orbital plane
  458.         final double x      = a * (cH - e);
  459.         final double y      = -a * sE2m1 * sH;
  460.         final double factor = FastMath.sqrt(getMu() / -a) / (e * cH - 1);
  461.         final double xDot   = -factor * sH;
  462.         final double yDot   =  factor * sE2m1 * cH;

  463.         final Vector3D shiftedP = new Vector3D(x, p, y, q);
  464.         final Vector3D shiftedV = new Vector3D(xDot, p, yDot, q);
  465.         if (hasNonKeplerianAcceleration) {

  466.             // extract non-Keplerian part of the initial acceleration
  467.             final Vector3D nonKeplerianAcceleration = new Vector3D(1, getPVCoordinates().getAcceleration(),
  468.                                                                    getMu() / (r2 * r), pvP);

  469.             // add the quadratic motion due to the non-Keplerian acceleration to the Keplerian motion
  470.             final Vector3D fixedP   = new Vector3D(1, shiftedP,
  471.                                                    0.5 * dt * dt, nonKeplerianAcceleration);
  472.             final double   fixedR2 = fixedP.getNormSq();
  473.             final double   fixedR  = FastMath.sqrt(fixedR2);
  474.             final Vector3D fixedV  = new Vector3D(1, shiftedV,
  475.                                                   dt, nonKeplerianAcceleration);
  476.             final Vector3D fixedA  = new Vector3D(-getMu() / (fixedR2 * fixedR), shiftedP,
  477.                                                   1, nonKeplerianAcceleration);

  478.             return new PVCoordinates(fixedP, fixedV, fixedA);

  479.         } else {
  480.             // don't include acceleration,
  481.             // so the shifted orbit is not considered to have derivatives
  482.             return new PVCoordinates(shiftedP, shiftedV);
  483.         }

  484.     }

  485.     @Override
  486.     protected double[][] computeJacobianMeanWrtCartesian() {
  487.         return SIX_BY_SIX_IDENTITY;
  488.     }

  489.     @Override
  490.     protected double[][] computeJacobianEccentricWrtCartesian() {
  491.         return SIX_BY_SIX_IDENTITY;
  492.     }

  493.     @Override
  494.     protected double[][] computeJacobianTrueWrtCartesian() {
  495.         return SIX_BY_SIX_IDENTITY;
  496.     }

  497.     /** {@inheritDoc} */
  498.     public void addKeplerContribution(final PositionAngleType type, final double gm,
  499.                                       final double[] pDot) {

  500.         final PVCoordinates pv = getPVCoordinates();

  501.         // position derivative is velocity
  502.         final Vector3D velocity = pv.getVelocity();
  503.         pDot[0] += velocity.getX();
  504.         pDot[1] += velocity.getY();
  505.         pDot[2] += velocity.getZ();

  506.         // velocity derivative is Newtonian acceleration
  507.         final Vector3D position = pv.getPosition();
  508.         final double r2         = position.getNormSq();
  509.         final double coeff      = -gm / (r2 * FastMath.sqrt(r2));
  510.         pDot[3] += coeff * position.getX();
  511.         pDot[4] += coeff * position.getY();
  512.         pDot[5] += coeff * position.getZ();

  513.     }

  514.     /**  Returns a string representation of this Orbit object.
  515.      * @return a string representation of this object
  516.      */
  517.     public String toString() {
  518.         // use only the six defining elements, like the other Orbit.toString() methods
  519.         final String comma = ", ";
  520.         final PVCoordinates pv = getPVCoordinates();
  521.         final Vector3D p = pv.getPosition();
  522.         final Vector3D v = pv.getVelocity();
  523.         return "Cartesian parameters: {P(" +
  524.                 p.getX() + comma +
  525.                 p.getY() + comma +
  526.                 p.getZ() + "), V(" +
  527.                 v.getX() + comma +
  528.                 v.getY() + comma +
  529.                 v.getZ() + ")}";
  530.     }

  531.     /** Replace the instance with a data transfer object for serialization.
  532.      * <p>
  533.      * This intermediate class serializes all needed parameters,
  534.      * including position-velocity which are <em>not</em> serialized by parent
  535.      * {@link Orbit} class.
  536.      * </p>
  537.      * @return data transfer object that will be serialized
  538.      */
  539.     @DefaultDataContext
  540.     private Object writeReplace() {
  541.         return new DTO(this);
  542.     }

  543.     /** Internal class used only for serialization. */
  544.     @DefaultDataContext
  545.     private static class DTO implements Serializable {

  546.         /** Serializable UID. */
  547.         private static final long serialVersionUID = 20170414L;

  548.         /** Double values. */
  549.         private double[] d;

  550.         /** Frame in which are defined the orbital parameters. */
  551.         private final Frame frame;

  552.         /** Simple constructor.
  553.          * @param orbit instance to serialize
  554.          */
  555.         private DTO(final CartesianOrbit orbit) {

  556.             final TimeStampedPVCoordinates pv = orbit.getPVCoordinates();

  557.             // decompose date
  558.             final AbsoluteDate j2000Epoch =
  559.                     DataContext.getDefault().getTimeScales().getJ2000Epoch();
  560.             final double epoch  = FastMath.floor(pv.getDate().durationFrom(j2000Epoch));
  561.             final double offset = pv.getDate().durationFrom(j2000Epoch.shiftedBy(epoch));

  562.             if (orbit.hasDerivatives()) {
  563.                 this.d = new double[] {
  564.                     epoch, offset, orbit.getMu(),
  565.                     pv.getPosition().getX(),     pv.getPosition().getY(),     pv.getPosition().getZ(),
  566.                     pv.getVelocity().getX(),     pv.getVelocity().getY(),     pv.getVelocity().getZ(),
  567.                     pv.getAcceleration().getX(), pv.getAcceleration().getY(), pv.getAcceleration().getZ()
  568.                 };
  569.             } else {
  570.                 this.d = new double[] {
  571.                     epoch, offset, orbit.getMu(),
  572.                     pv.getPosition().getX(),     pv.getPosition().getY(),     pv.getPosition().getZ(),
  573.                     pv.getVelocity().getX(),     pv.getVelocity().getY(),     pv.getVelocity().getZ()
  574.                 };
  575.             }

  576.             this.frame = orbit.getFrame();

  577.         }

  578.         /** Replace the deserialized data transfer object with a {@link CartesianOrbit}.
  579.          * @return replacement {@link CartesianOrbit}
  580.          */
  581.         private Object readResolve() {
  582.             final AbsoluteDate j2000Epoch =
  583.                     DataContext.getDefault().getTimeScales().getJ2000Epoch();
  584.             if (d.length >= 12) {
  585.                 // we have derivatives
  586.                 return new CartesianOrbit(new TimeStampedPVCoordinates(j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
  587.                                                                        new Vector3D(d[3], d[ 4], d[ 5]),
  588.                                                                        new Vector3D(d[6], d[ 7], d[ 8]),
  589.                                                                        new Vector3D(d[9], d[10], d[11])),
  590.                                           frame, d[2]);
  591.             } else {
  592.                 // we don't have derivatives
  593.                 return new CartesianOrbit(new TimeStampedPVCoordinates(j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
  594.                                                                        new Vector3D(d[3], d[ 4], d[ 5]),
  595.                                                                        new Vector3D(d[6], d[ 7], d[ 8])),
  596.                                           frame, d[2]);
  597.             }
  598.         }

  599.     }

  600. }