EquinoctialOrbit.java

  1. /* Copyright 2002-2024 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.UnivariateDerivative1;
  20. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.hipparchus.util.SinCos;
  23. import org.orekit.annotation.DefaultDataContext;
  24. import org.orekit.data.DataContext;
  25. import org.orekit.errors.OrekitIllegalArgumentException;
  26. import org.orekit.errors.OrekitInternalError;
  27. import org.orekit.errors.OrekitMessages;
  28. import org.orekit.frames.Frame;
  29. import org.orekit.time.AbsoluteDate;
  30. import org.orekit.utils.PVCoordinates;
  31. import org.orekit.utils.TimeStampedPVCoordinates;


  32. /**
  33.  * This class handles equinoctial orbital parameters, which can support both
  34.  * circular and equatorial orbits.
  35.  * <p>
  36.  * The parameters used internally are the equinoctial elements which can be
  37.  * related to Keplerian elements as follows:
  38.  *   <pre>
  39.  *     a
  40.  *     ex = e cos(ω + Ω)
  41.  *     ey = e sin(ω + Ω)
  42.  *     hx = tan(i/2) cos(Ω)
  43.  *     hy = tan(i/2) sin(Ω)
  44.  *     lv = v + ω + Ω
  45.  *   </pre>
  46.  * where ω stands for the Perigee Argument and Ω stands for the
  47.  * Right Ascension of the Ascending Node.
  48.  *
  49.  * <p>
  50.  * The conversion equations from and to Keplerian elements given above hold only
  51.  * when both sides are unambiguously defined, i.e. when orbit is neither equatorial
  52.  * nor circular. When orbit is either equatorial or circular, the equinoctial
  53.  * parameters are still unambiguously defined whereas some Keplerian elements
  54.  * (more precisely ω and Ω) become ambiguous. For this reason, equinoctial
  55.  * parameters are the recommended way to represent orbits. Note however than
  56.  * the present implementation does not handle non-elliptical cases.
  57.  * </p>
  58.  * <p>
  59.  * The instance <code>EquinoctialOrbit</code> is guaranteed to be immutable.
  60.  * </p>
  61.  * @see    Orbit
  62.  * @see    KeplerianOrbit
  63.  * @see    CircularOrbit
  64.  * @see    CartesianOrbit
  65.  * @author Mathieu Rom&eacute;ro
  66.  * @author Luc Maisonobe
  67.  * @author Guylaine Prat
  68.  * @author Fabien Maussion
  69.  * @author V&eacute;ronique Pommier-Maurussane
  70.  */
  71. public class EquinoctialOrbit extends Orbit implements PositionAngleBased {

  72.     /** Serializable UID. */
  73.     private static final long serialVersionUID = 20170414L;

  74.     /** Semi-major axis (m). */
  75.     private final double a;

  76.     /** First component of the eccentricity vector. */
  77.     private final double ex;

  78.     /** Second component of the eccentricity vector. */
  79.     private final double ey;

  80.     /** First component of the inclination vector. */
  81.     private final double hx;

  82.     /** Second component of the inclination vector. */
  83.     private final double hy;

  84.     /** Cached longitude argument (rad). */
  85.     private final double cachedL;

  86.     /** Cache type of position angle (longitude argument). */
  87.     private final PositionAngleType cachedPositionAngleType;

  88.     /** Semi-major axis derivative (m/s). */
  89.     private final double aDot;

  90.     /** First component of the eccentricity vector derivative. */
  91.     private final double exDot;

  92.     /** Second component of the eccentricity vector derivative. */
  93.     private final double eyDot;

  94.     /** First component of the inclination vector derivative. */
  95.     private final double hxDot;

  96.     /** Second component of the inclination vector derivative. */
  97.     private final double hyDot;

  98.     /** Derivative of cached longitude argument (rad/s). */
  99.     private final double cachedLDot;

  100.     /** Partial Cartesian coordinates (position and velocity are valid, acceleration may be missing). */
  101.     private transient PVCoordinates partialPV;

  102.     /** Creates a new instance.
  103.      * @param a  semi-major axis (m)
  104.      * @param ex e cos(ω + Ω), first component of eccentricity vector
  105.      * @param ey e sin(ω + Ω), second component of eccentricity vector
  106.      * @param hx tan(i/2) cos(Ω), first component of inclination vector
  107.      * @param hy tan(i/2) sin(Ω), second component of inclination vector
  108.      * @param l  (M or E or v) + ω + Ω, mean, eccentric or true longitude argument (rad)
  109.      * @param type type of longitude argument
  110.      * @param cachedPositionAngleType type of cached longitude argument
  111.      * @param frame the frame in which the parameters are defined
  112.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  113.      * @param date date of the orbital parameters
  114.      * @param mu central attraction coefficient (m³/s²)
  115.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  116.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  117.      * @since 12.1
  118.      */
  119.     public EquinoctialOrbit(final double a, final double ex, final double ey,
  120.                             final double hx, final double hy, final double l,
  121.                             final PositionAngleType type, final PositionAngleType cachedPositionAngleType,
  122.                             final Frame frame, final AbsoluteDate date, final double mu)
  123.         throws IllegalArgumentException {
  124.         this(a, ex, ey, hx, hy, l,
  125.              Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN,
  126.              type, cachedPositionAngleType, frame, date, mu);
  127.     }

  128.     /** Creates a new instance without derivatives and with cached position angle same as value inputted.
  129.      * @param a  semi-major axis (m)
  130.      * @param ex e cos(ω + Ω), first component of eccentricity vector
  131.      * @param ey e sin(ω + Ω), second component of eccentricity vector
  132.      * @param hx tan(i/2) cos(Ω), first component of inclination vector
  133.      * @param hy tan(i/2) sin(Ω), second component of inclination vector
  134.      * @param l  (M or E or v) + ω + Ω, mean, eccentric or true longitude argument (rad)
  135.      * @param type type of longitude argument
  136.      * @param frame the frame in which the parameters are defined
  137.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  138.      * @param date date of the orbital parameters
  139.      * @param mu central attraction coefficient (m³/s²)
  140.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  141.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  142.      */
  143.     public EquinoctialOrbit(final double a, final double ex, final double ey,
  144.                             final double hx, final double hy, final double l,
  145.                             final PositionAngleType type,
  146.                             final Frame frame, final AbsoluteDate date, final double mu)
  147.             throws IllegalArgumentException {
  148.         this(a, ex, ey, hx, hy, l, type, type, frame, date, mu);
  149.     }

  150.     /** Creates a new instance.
  151.      * @param a  semi-major axis (m)
  152.      * @param ex e cos(ω + Ω), first component of eccentricity vector
  153.      * @param ey e sin(ω + Ω), second component of eccentricity vector
  154.      * @param hx tan(i/2) cos(Ω), first component of inclination vector
  155.      * @param hy tan(i/2) sin(Ω), second component of inclination vector
  156.      * @param l  (M or E or v) + ω + Ω, mean, eccentric or true longitude argument (rad)
  157.      * @param aDot  semi-major axis derivative (m/s)
  158.      * @param exDot d(e cos(ω + Ω))/dt, first component of eccentricity vector derivative
  159.      * @param eyDot d(e sin(ω + Ω))/dt, second component of eccentricity vector derivative
  160.      * @param hxDot d(tan(i/2) cos(Ω))/dt, first component of inclination vector derivative
  161.      * @param hyDot d(tan(i/2) sin(Ω))/dt, second component of inclination vector derivative
  162.      * @param lDot  d(M or E or v) + ω + Ω)/dr, mean, eccentric or true longitude argument  derivative (rad/s)
  163.      * @param type type of longitude argument
  164.      * @param cachedPositionAngleType of cached longitude argument
  165.      * @param frame the frame in which the parameters are defined
  166.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  167.      * @param date date of the orbital parameters
  168.      * @param mu central attraction coefficient (m³/s²)
  169.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  170.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  171.      * @since 12.1
  172.      */
  173.     public EquinoctialOrbit(final double a, final double ex, final double ey,
  174.                             final double hx, final double hy, final double l,
  175.                             final double aDot, final double exDot, final double eyDot,
  176.                             final double hxDot, final double hyDot, final double lDot,
  177.                             final PositionAngleType type, final PositionAngleType cachedPositionAngleType,
  178.                             final Frame frame, final AbsoluteDate date, final double mu)
  179.         throws IllegalArgumentException {
  180.         super(frame, date, mu);
  181.         if (ex * ex + ey * ey >= 1.0) {
  182.             throw new OrekitIllegalArgumentException(OrekitMessages.HYPERBOLIC_ORBIT_NOT_HANDLED_AS,
  183.                                                      getClass().getName());
  184.         }
  185.         this.cachedPositionAngleType = cachedPositionAngleType;
  186.         this.a     = a;
  187.         this.aDot  = aDot;
  188.         this.ex    = ex;
  189.         this.exDot = exDot;
  190.         this.ey    = ey;
  191.         this.eyDot = eyDot;
  192.         this.hx    = hx;
  193.         this.hxDot = hxDot;
  194.         this.hy    = hy;
  195.         this.hyDot = hyDot;

  196.         if (hasDerivatives()) {
  197.             final UnivariateDerivative1 lUD = initializeCachedL(l, lDot, type);
  198.             this.cachedL = lUD.getValue();
  199.             this.cachedLDot = lUD.getFirstDerivative();
  200.         } else {
  201.             this.cachedL = initializeCachedL(l, type);
  202.             this.cachedLDot = Double.NaN;
  203.         }

  204.         this.partialPV = null;

  205.     }

  206.     /** Creates a new instance with derivatives and with cached position angle same as value inputted.
  207.      * @param a  semi-major axis (m)
  208.      * @param ex e cos(ω + Ω), first component of eccentricity vector
  209.      * @param ey e sin(ω + Ω), second component of eccentricity vector
  210.      * @param hx tan(i/2) cos(Ω), first component of inclination vector
  211.      * @param hy tan(i/2) sin(Ω), second component of inclination vector
  212.      * @param l  (M or E or v) + ω + Ω, mean, eccentric or true longitude argument (rad)
  213.      * @param aDot  semi-major axis derivative (m/s)
  214.      * @param exDot d(e cos(ω + Ω))/dt, first component of eccentricity vector derivative
  215.      * @param eyDot d(e sin(ω + Ω))/dt, second component of eccentricity vector derivative
  216.      * @param hxDot d(tan(i/2) cos(Ω))/dt, first component of inclination vector derivative
  217.      * @param hyDot d(tan(i/2) sin(Ω))/dt, second component of inclination vector derivative
  218.      * @param lDot  d(M or E or v) + ω + Ω)/dr, mean, eccentric or true longitude argument  derivative (rad/s)
  219.      * @param type type of longitude argument
  220.      * @param frame the frame in which the parameters are defined
  221.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  222.      * @param date date of the orbital parameters
  223.      * @param mu central attraction coefficient (m³/s²)
  224.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  225.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  226.      */
  227.     public EquinoctialOrbit(final double a, final double ex, final double ey,
  228.                             final double hx, final double hy, final double l,
  229.                             final double aDot, final double exDot, final double eyDot,
  230.                             final double hxDot, final double hyDot, final double lDot,
  231.                             final PositionAngleType type,
  232.                             final Frame frame, final AbsoluteDate date, final double mu)
  233.             throws IllegalArgumentException {
  234.         this(a, ex, ey, hx, hy, l, aDot, exDot, eyDot, hxDot, hyDot, lDot, type, type, frame, date, mu);
  235.     }

  236.     /** Constructor from Cartesian parameters.
  237.      *
  238.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  239.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  240.      * use {@code mu} and the position to compute the acceleration, including
  241.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  242.      *
  243.      * @param pvCoordinates the position, velocity and acceleration
  244.      * @param frame the frame in which are defined the {@link PVCoordinates}
  245.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  246.      * @param mu central attraction coefficient (m³/s²)
  247.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  248.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  249.      */
  250.     public EquinoctialOrbit(final TimeStampedPVCoordinates pvCoordinates,
  251.                             final Frame frame, final double mu)
  252.         throws IllegalArgumentException {
  253.         super(pvCoordinates, frame, mu);

  254.         //  compute semi-major axis
  255.         final Vector3D pvP   = pvCoordinates.getPosition();
  256.         final Vector3D pvV   = pvCoordinates.getVelocity();
  257.         final Vector3D pvA   = pvCoordinates.getAcceleration();
  258.         final double r2      = pvP.getNormSq();
  259.         final double r       = FastMath.sqrt(r2);
  260.         final double V2      = pvV.getNormSq();
  261.         final double rV2OnMu = r * V2 / mu;

  262.         // compute semi-major axis
  263.         a = r / (2 - rV2OnMu);

  264.         if (!isElliptical()) {
  265.             throw new OrekitIllegalArgumentException(OrekitMessages.HYPERBOLIC_ORBIT_NOT_HANDLED_AS,
  266.                                                      getClass().getName());
  267.         }

  268.         // compute inclination vector
  269.         final Vector3D w = pvCoordinates.getMomentum().normalize();
  270.         final double d = 1.0 / (1 + w.getZ());
  271.         hx = -d * w.getY();
  272.         hy =  d * w.getX();

  273.         // compute true longitude argument
  274.         cachedPositionAngleType = PositionAngleType.TRUE;
  275.         final double cLv = (pvP.getX() - d * pvP.getZ() * w.getX()) / r;
  276.         final double sLv = (pvP.getY() - d * pvP.getZ() * w.getY()) / r;
  277.         cachedL = FastMath.atan2(sLv, cLv);

  278.         // compute eccentricity vector
  279.         final double eSE = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(mu * a);
  280.         final double eCE = rV2OnMu - 1;
  281.         final double e2  = eCE * eCE + eSE * eSE;
  282.         final double f   = eCE - e2;
  283.         final double g   = FastMath.sqrt(1 - e2) * eSE;
  284.         ex = a * (f * cLv + g * sLv) / r;
  285.         ey = a * (f * sLv - g * cLv) / r;

  286.         partialPV = pvCoordinates;

  287.         if (hasNonKeplerianAcceleration(pvCoordinates, mu)) {
  288.             // we have a relevant acceleration, we can compute derivatives

  289.             final double[][] jacobian = new double[6][6];
  290.             getJacobianWrtCartesian(PositionAngleType.MEAN, jacobian);

  291.             final Vector3D keplerianAcceleration    = new Vector3D(-mu / (r * r2), pvP);
  292.             final Vector3D nonKeplerianAcceleration = pvA.subtract(keplerianAcceleration);
  293.             final double   aX                       = nonKeplerianAcceleration.getX();
  294.             final double   aY                       = nonKeplerianAcceleration.getY();
  295.             final double   aZ                       = nonKeplerianAcceleration.getZ();
  296.             aDot  = jacobian[0][3] * aX + jacobian[0][4] * aY + jacobian[0][5] * aZ;
  297.             exDot = jacobian[1][3] * aX + jacobian[1][4] * aY + jacobian[1][5] * aZ;
  298.             eyDot = jacobian[2][3] * aX + jacobian[2][4] * aY + jacobian[2][5] * aZ;
  299.             hxDot = jacobian[3][3] * aX + jacobian[3][4] * aY + jacobian[3][5] * aZ;
  300.             hyDot = jacobian[4][3] * aX + jacobian[4][4] * aY + jacobian[4][5] * aZ;

  301.             // in order to compute true longitude argument derivative, we must compute
  302.             // mean longitude argument derivative including Keplerian motion and convert to true longitude argument
  303.             final double lMDot = getKeplerianMeanMotion() +
  304.                                  jacobian[5][3] * aX + jacobian[5][4] * aY + jacobian[5][5] * aZ;
  305.             final UnivariateDerivative1 exUD = new UnivariateDerivative1(ex, exDot);
  306.             final UnivariateDerivative1 eyUD = new UnivariateDerivative1(ey, eyDot);
  307.             final UnivariateDerivative1 lMUD = new UnivariateDerivative1(getLM(), lMDot);
  308.             final UnivariateDerivative1 lvUD = FieldEquinoctialLongitudeArgumentUtility.meanToTrue(exUD, eyUD, lMUD);
  309.             cachedLDot = lvUD.getFirstDerivative();

  310.         } else {
  311.             // acceleration is either almost zero or NaN,
  312.             // we assume acceleration was not known
  313.             // we don't set up derivatives
  314.             aDot  = Double.NaN;
  315.             exDot = Double.NaN;
  316.             eyDot = Double.NaN;
  317.             hxDot = Double.NaN;
  318.             hyDot = Double.NaN;
  319.             cachedLDot = Double.NaN;
  320.         }

  321.     }

  322.     /** Constructor from Cartesian parameters.
  323.      *
  324.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  325.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  326.      * use {@code mu} and the position to compute the acceleration, including
  327.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  328.      *
  329.      * @param pvCoordinates the position end velocity
  330.      * @param frame the frame in which are defined the {@link PVCoordinates}
  331.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  332.      * @param date date of the orbital parameters
  333.      * @param mu central attraction coefficient (m³/s²)
  334.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  335.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  336.      */
  337.     public EquinoctialOrbit(final PVCoordinates pvCoordinates, final Frame frame,
  338.                             final AbsoluteDate date, final double mu)
  339.         throws IllegalArgumentException {
  340.         this(new TimeStampedPVCoordinates(date, pvCoordinates), frame, mu);
  341.     }

  342.     /** Constructor from any kind of orbital parameters.
  343.      * @param op orbital parameters to copy
  344.      */
  345.     public EquinoctialOrbit(final Orbit op) {
  346.         super(op.getFrame(), op.getDate(), op.getMu());
  347.         a         = op.getA();
  348.         aDot      = op.getADot();
  349.         ex        = op.getEquinoctialEx();
  350.         exDot     = op.getEquinoctialExDot();
  351.         ey        = op.getEquinoctialEy();
  352.         eyDot     = op.getEquinoctialEyDot();
  353.         hx        = op.getHx();
  354.         hxDot     = op.getHxDot();
  355.         hy        = op.getHy();
  356.         hyDot     = op.getHyDot();
  357.         cachedPositionAngleType = PositionAngleType.TRUE;
  358.         cachedL   = op.getLv();
  359.         cachedLDot = op.getLvDot();
  360.         partialPV = null;
  361.     }

  362.     /** {@inheritDoc} */
  363.     @Override
  364.     public OrbitType getType() {
  365.         return OrbitType.EQUINOCTIAL;
  366.     }

  367.     /** {@inheritDoc} */
  368.     @Override
  369.     public double getA() {
  370.         return a;
  371.     }

  372.     /** {@inheritDoc} */
  373.     @Override
  374.     public double getADot() {
  375.         return aDot;
  376.     }

  377.     /** {@inheritDoc} */
  378.     @Override
  379.     public double getEquinoctialEx() {
  380.         return ex;
  381.     }

  382.     /** {@inheritDoc} */
  383.     @Override
  384.     public double getEquinoctialExDot() {
  385.         return exDot;
  386.     }

  387.     /** {@inheritDoc} */
  388.     @Override
  389.     public double getEquinoctialEy() {
  390.         return ey;
  391.     }

  392.     /** {@inheritDoc} */
  393.     @Override
  394.     public double getEquinoctialEyDot() {
  395.         return eyDot;
  396.     }

  397.     /** {@inheritDoc} */
  398.     @Override
  399.     public double getHx() {
  400.         return hx;
  401.     }

  402.     /** {@inheritDoc} */
  403.     @Override
  404.     public double getHxDot() {
  405.         return hxDot;
  406.     }

  407.     /** {@inheritDoc} */
  408.     @Override
  409.     public double getHy() {
  410.         return hy;
  411.     }

  412.     /** {@inheritDoc} */
  413.     @Override
  414.     public double getHyDot() {
  415.         return hyDot;
  416.     }

  417.     /** {@inheritDoc} */
  418.     @Override
  419.     public double getLv() {
  420.         switch (cachedPositionAngleType) {
  421.             case TRUE:
  422.                 return cachedL;

  423.             case ECCENTRIC:
  424.                 return EquinoctialLongitudeArgumentUtility.eccentricToTrue(ex, ey, cachedL);

  425.             case MEAN:
  426.                 return EquinoctialLongitudeArgumentUtility.meanToTrue(ex, ey, cachedL);

  427.             default:
  428.                 throw new OrekitInternalError(null);
  429.         }
  430.     }

  431.     /** {@inheritDoc} */
  432.     @Override
  433.     public double getLvDot() {
  434.         switch (cachedPositionAngleType) {
  435.             case ECCENTRIC:
  436.                 final UnivariateDerivative1 lEUD = new UnivariateDerivative1(cachedL, cachedLDot);
  437.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  438.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  439.                 final UnivariateDerivative1 lvUD = FieldEquinoctialLongitudeArgumentUtility.eccentricToTrue(exUD, eyUD,
  440.                         lEUD);
  441.                 return lvUD.getFirstDerivative();

  442.             case TRUE:
  443.                 return cachedLDot;

  444.             case MEAN:
  445.                 final UnivariateDerivative1 lMUD = new UnivariateDerivative1(cachedL, cachedLDot);
  446.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  447.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  448.                 final UnivariateDerivative1 lvUD2 = FieldEquinoctialLongitudeArgumentUtility.meanToTrue(exUD2,
  449.                         eyUD2, lMUD);
  450.                 return lvUD2.getFirstDerivative();

  451.             default:
  452.                 throw new OrekitInternalError(null);
  453.         }
  454.     }

  455.     /** {@inheritDoc} */
  456.     @Override
  457.     public double getLE() {
  458.         switch (cachedPositionAngleType) {
  459.             case TRUE:
  460.                 return EquinoctialLongitudeArgumentUtility.trueToEccentric(ex, ey, cachedL);

  461.             case ECCENTRIC:
  462.                 return cachedL;

  463.             case MEAN:
  464.                 return EquinoctialLongitudeArgumentUtility.meanToEccentric(ex, ey, cachedL);

  465.             default:
  466.                 throw new OrekitInternalError(null);
  467.         }
  468.     }

  469.     /** {@inheritDoc} */
  470.     @Override
  471.     public double getLEDot() {
  472.         switch (cachedPositionAngleType) {
  473.             case TRUE:
  474.                 final UnivariateDerivative1 lvUD = new UnivariateDerivative1(cachedL, cachedLDot);
  475.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  476.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  477.                 final UnivariateDerivative1 lEUD = FieldEquinoctialLongitudeArgumentUtility.trueToEccentric(exUD, eyUD,
  478.                         lvUD);
  479.                 return lEUD.getFirstDerivative();

  480.             case ECCENTRIC:
  481.                 return cachedLDot;

  482.             case MEAN:
  483.                 final UnivariateDerivative1 lMUD = new UnivariateDerivative1(cachedL, cachedLDot);
  484.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  485.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  486.                 final UnivariateDerivative1 lEUD2 = FieldEquinoctialLongitudeArgumentUtility.meanToEccentric(exUD2,
  487.                         eyUD2, lMUD);
  488.                 return lEUD2.getFirstDerivative();

  489.             default:
  490.                 throw new OrekitInternalError(null);
  491.         }
  492.     }

  493.     /** {@inheritDoc} */
  494.     @Override
  495.     public double getLM() {
  496.         switch (cachedPositionAngleType) {
  497.             case TRUE:
  498.                 return EquinoctialLongitudeArgumentUtility.trueToMean(ex, ey, cachedL);

  499.             case MEAN:
  500.                 return cachedL;

  501.             case ECCENTRIC:
  502.                 return EquinoctialLongitudeArgumentUtility.eccentricToMean(ex, ey, cachedL);

  503.             default:
  504.                 throw new OrekitInternalError(null);
  505.         }
  506.     }

  507.     /** {@inheritDoc} */
  508.     @Override
  509.     public double getLMDot() {
  510.         switch (cachedPositionAngleType) {
  511.             case TRUE:
  512.                 final UnivariateDerivative1 lvUD = new UnivariateDerivative1(cachedL, cachedLDot);
  513.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  514.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  515.                 final UnivariateDerivative1 lMUD = FieldEquinoctialLongitudeArgumentUtility.trueToMean(exUD, eyUD, lvUD);
  516.                 return lMUD.getFirstDerivative();

  517.             case MEAN:
  518.                 return cachedLDot;

  519.             case ECCENTRIC:
  520.                 final UnivariateDerivative1 lEUD = new UnivariateDerivative1(cachedL, cachedLDot);
  521.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  522.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  523.                 final UnivariateDerivative1 lMUD2 = FieldEquinoctialLongitudeArgumentUtility.eccentricToMean(exUD2,
  524.                         eyUD2, lEUD);
  525.                 return lMUD2.getFirstDerivative();

  526.             default:
  527.                 throw new OrekitInternalError(null);
  528.         }
  529.     }

  530.     /** Get the longitude argument.
  531.      * @param type type of the angle
  532.      * @return longitude argument (rad)
  533.      */
  534.     public double getL(final PositionAngleType type) {
  535.         return (type == PositionAngleType.MEAN) ? getLM() :
  536.                                               ((type == PositionAngleType.ECCENTRIC) ? getLE() :
  537.                                                                                    getLv());
  538.     }

  539.     /** Get the longitude argument derivative.
  540.      * @param type type of the angle
  541.      * @return longitude argument derivative (rad/s)
  542.      */
  543.     public double getLDot(final PositionAngleType type) {
  544.         return (type == PositionAngleType.MEAN) ? getLMDot() :
  545.                                               ((type == PositionAngleType.ECCENTRIC) ? getLEDot() :
  546.                                                                                    getLvDot());
  547.     }

  548.     /** Computes the true longitude argument from the eccentric longitude argument.
  549.      * @param lE = E + ω + Ω eccentric longitude argument (rad)
  550.      * @param ex first component of the eccentricity vector
  551.      * @param ey second component of the eccentricity vector
  552.      * @return the true longitude argument
  553.      */
  554.     @Deprecated
  555.     public static double eccentricToTrue(final double lE, final double ex, final double ey) {
  556.         return EquinoctialLongitudeArgumentUtility.eccentricToTrue(ex, ey, lE);
  557.     }

  558.     /** Computes the eccentric longitude argument from the true longitude argument.
  559.      * @param lv = v + ω + Ω true longitude argument (rad)
  560.      * @param ex first component of the eccentricity vector
  561.      * @param ey second component of the eccentricity vector
  562.      * @return the eccentric longitude argument
  563.      */
  564.     @Deprecated
  565.     public static double trueToEccentric(final double lv, final double ex, final double ey) {
  566.         return EquinoctialLongitudeArgumentUtility.trueToEccentric(ex, ey, lv);
  567.     }

  568.     /** Computes the eccentric longitude argument from the mean longitude argument.
  569.      * @param lM = M + ω + Ω mean longitude argument (rad)
  570.      * @param ex first component of the eccentricity vector
  571.      * @param ey second component of the eccentricity vector
  572.      * @return the eccentric longitude argument
  573.      */
  574.     @Deprecated
  575.     public static double meanToEccentric(final double lM, final double ex, final double ey) {
  576.         return EquinoctialLongitudeArgumentUtility.meanToEccentric(ex, ey, lM);
  577.     }

  578.     /** Computes the mean longitude argument from the eccentric longitude argument.
  579.      * @param lE = E + ω + Ω mean longitude argument (rad)
  580.      * @param ex first component of the eccentricity vector
  581.      * @param ey second component of the eccentricity vector
  582.      * @return the mean longitude argument
  583.      */
  584.     @Deprecated
  585.     public static double eccentricToMean(final double lE, final double ex, final double ey) {
  586.         return EquinoctialLongitudeArgumentUtility.eccentricToMean(ex, ey, lE);
  587.     }

  588.     /** {@inheritDoc} */
  589.     @Override
  590.     public double getE() {
  591.         return FastMath.sqrt(ex * ex + ey * ey);
  592.     }

  593.     /** {@inheritDoc} */
  594.     @Override
  595.     public double getEDot() {
  596.         return (ex * exDot + ey * eyDot) / FastMath.sqrt(ex * ex + ey * ey);
  597.     }

  598.     /** {@inheritDoc} */
  599.     @Override
  600.     public double getI() {
  601.         return 2 * FastMath.atan(FastMath.sqrt(hx * hx + hy * hy));
  602.     }

  603.     /** {@inheritDoc} */
  604.     @Override
  605.     public double getIDot() {
  606.         final double h2 = hx * hx + hy * hy;
  607.         final double h  = FastMath.sqrt(h2);
  608.         return 2 * (hx * hxDot + hy * hyDot) / (h * (1 + h2));
  609.     }

  610.     /** Compute position and velocity but not acceleration.
  611.      */
  612.     private void computePVWithoutA() {

  613.         if (partialPV != null) {
  614.             // already computed
  615.             return;
  616.         }

  617.         // get equinoctial parameters
  618.         final double lE = getLE();

  619.         // inclination-related intermediate parameters
  620.         final double hx2   = hx * hx;
  621.         final double hy2   = hy * hy;
  622.         final double factH = 1. / (1 + hx2 + hy2);

  623.         // reference axes defining the orbital plane
  624.         final double ux = (1 + hx2 - hy2) * factH;
  625.         final double uy =  2 * hx * hy * factH;
  626.         final double uz = -2 * hy * factH;

  627.         final double vx = uy;
  628.         final double vy = (1 - hx2 + hy2) * factH;
  629.         final double vz =  2 * hx * factH;

  630.         // eccentricity-related intermediate parameters
  631.         final double exey = ex * ey;
  632.         final double ex2  = ex * ex;
  633.         final double ey2  = ey * ey;
  634.         final double e2   = ex2 + ey2;
  635.         final double eta  = 1 + FastMath.sqrt(1 - e2);
  636.         final double beta = 1. / eta;

  637.         // eccentric longitude argument
  638.         final SinCos scLe   = FastMath.sinCos(lE);
  639.         final double cLe    = scLe.cos();
  640.         final double sLe    = scLe.sin();
  641.         final double exCeyS = ex * cLe + ey * sLe;

  642.         // coordinates of position and velocity in the orbital plane
  643.         final double x      = a * ((1 - beta * ey2) * cLe + beta * exey * sLe - ex);
  644.         final double y      = a * ((1 - beta * ex2) * sLe + beta * exey * cLe - ey);

  645.         final double factor = FastMath.sqrt(getMu() / a) / (1 - exCeyS);
  646.         final double xdot   = factor * (-sLe + beta * ey * exCeyS);
  647.         final double ydot   = factor * ( cLe - beta * ex * exCeyS);

  648.         final Vector3D position =
  649.                         new Vector3D(x * ux + y * vx, x * uy + y * vy, x * uz + y * vz);
  650.         final Vector3D velocity =
  651.                         new Vector3D(xdot * ux + ydot * vx, xdot * uy + ydot * vy, xdot * uz + ydot * vz);
  652.         partialPV = new PVCoordinates(position, velocity);

  653.     }

  654.     /** Initialize cached argument of longitude with rate.
  655.      * @param l input argument of longitude
  656.      * @param lDot rate of input argument of longitude
  657.      * @param inputType position angle type passed as input
  658.      * @return argument of longitude to cache with rate
  659.      * @since 12.1
  660.      */
  661.     private UnivariateDerivative1 initializeCachedL(final double l, final double lDot,
  662.                                                     final PositionAngleType inputType) {
  663.         if (cachedPositionAngleType == inputType) {
  664.             return new UnivariateDerivative1(l, lDot);

  665.         } else {
  666.             final UnivariateDerivative1 exUD = new UnivariateDerivative1(ex, exDot);
  667.             final UnivariateDerivative1 eyUD = new UnivariateDerivative1(ey, eyDot);
  668.             final UnivariateDerivative1 lUD = new UnivariateDerivative1(l, lDot);

  669.             switch (cachedPositionAngleType) {

  670.                 case ECCENTRIC:
  671.                     if (inputType == PositionAngleType.MEAN) {
  672.                         return FieldEquinoctialLongitudeArgumentUtility.meanToEccentric(exUD, eyUD, lUD);
  673.                     } else {
  674.                         return FieldEquinoctialLongitudeArgumentUtility.trueToEccentric(exUD, eyUD, lUD);
  675.                     }

  676.                 case TRUE:
  677.                     if (inputType == PositionAngleType.MEAN) {
  678.                         return FieldEquinoctialLongitudeArgumentUtility.meanToTrue(exUD, eyUD, lUD);
  679.                     } else {
  680.                         return FieldEquinoctialLongitudeArgumentUtility.eccentricToTrue(exUD, eyUD, lUD);
  681.                     }

  682.                 case MEAN:
  683.                     if (inputType == PositionAngleType.TRUE) {
  684.                         return FieldEquinoctialLongitudeArgumentUtility.trueToMean(exUD, eyUD, lUD);
  685.                     } else {
  686.                         return FieldEquinoctialLongitudeArgumentUtility.eccentricToMean(exUD, eyUD, lUD);
  687.                     }

  688.                 default:
  689.                     throw new OrekitInternalError(null);

  690.             }

  691.         }

  692.     }

  693.     /** Initialize cached argument of longitude.
  694.      * @param l input argument of longitude
  695.      * @param positionAngleType position angle type passed as input
  696.      * @return argument of longitude to cache
  697.      * @since 12.1
  698.      */
  699.     private double initializeCachedL(final double l, final PositionAngleType positionAngleType) {
  700.         return EquinoctialLongitudeArgumentUtility.convertL(positionAngleType, l, ex, ey, cachedPositionAngleType);
  701.     }

  702.     /** Compute non-Keplerian part of the acceleration from first time derivatives.
  703.      * <p>
  704.      * This method should be called only when {@link #hasDerivatives()} returns true.
  705.      * </p>
  706.      * @return non-Keplerian part of the acceleration
  707.      */
  708.     private Vector3D nonKeplerianAcceleration() {

  709.         final double[][] dCdP = new double[6][6];
  710.         getJacobianWrtParameters(PositionAngleType.MEAN, dCdP);

  711.         final double nonKeplerianMeanMotion = getLMDot() - getKeplerianMeanMotion();
  712.         final double nonKeplerianAx = dCdP[3][0] * aDot  + dCdP[3][1] * exDot + dCdP[3][2] * eyDot +
  713.                                       dCdP[3][3] * hxDot + dCdP[3][4] * hyDot + dCdP[3][5] * nonKeplerianMeanMotion;
  714.         final double nonKeplerianAy = dCdP[4][0] * aDot  + dCdP[4][1] * exDot + dCdP[4][2] * eyDot +
  715.                                       dCdP[4][3] * hxDot + dCdP[4][4] * hyDot + dCdP[4][5] * nonKeplerianMeanMotion;
  716.         final double nonKeplerianAz = dCdP[5][0] * aDot  + dCdP[5][1] * exDot + dCdP[5][2] * eyDot +
  717.                                       dCdP[5][3] * hxDot + dCdP[5][4] * hyDot + dCdP[5][5] * nonKeplerianMeanMotion;

  718.         return new Vector3D(nonKeplerianAx, nonKeplerianAy, nonKeplerianAz);

  719.     }

  720.     /** {@inheritDoc} */
  721.     @Override
  722.     protected Vector3D initPosition() {

  723.         // get equinoctial parameters
  724.         final double lE = getLE();

  725.         // inclination-related intermediate parameters
  726.         final double hx2   = hx * hx;
  727.         final double hy2   = hy * hy;
  728.         final double factH = 1. / (1 + hx2 + hy2);

  729.         // reference axes defining the orbital plane
  730.         final double ux = (1 + hx2 - hy2) * factH;
  731.         final double uy =  2 * hx * hy * factH;
  732.         final double uz = -2 * hy * factH;

  733.         final double vx = uy;
  734.         final double vy = (1 - hx2 + hy2) * factH;
  735.         final double vz =  2 * hx * factH;

  736.         // eccentricity-related intermediate parameters
  737.         final double exey = ex * ey;
  738.         final double ex2  = ex * ex;
  739.         final double ey2  = ey * ey;
  740.         final double e2   = ex2 + ey2;
  741.         final double eta  = 1 + FastMath.sqrt(1 - e2);
  742.         final double beta = 1. / eta;

  743.         // eccentric longitude argument
  744.         final SinCos scLe   = FastMath.sinCos(lE);
  745.         final double cLe    = scLe.cos();
  746.         final double sLe    = scLe.sin();

  747.         // coordinates of position and velocity in the orbital plane
  748.         final double x      = a * ((1 - beta * ey2) * cLe + beta * exey * sLe - ex);
  749.         final double y      = a * ((1 - beta * ex2) * sLe + beta * exey * cLe - ey);

  750.         return new Vector3D(x * ux + y * vx, x * uy + y * vy, x * uz + y * vz);

  751.     }

  752.     /** {@inheritDoc} */
  753.     @Override
  754.     protected TimeStampedPVCoordinates initPVCoordinates() {

  755.         // position and velocity
  756.         computePVWithoutA();

  757.         // acceleration
  758.         final double r2 = partialPV.getPosition().getNormSq();
  759.         final Vector3D keplerianAcceleration = new Vector3D(-getMu() / (r2 * FastMath.sqrt(r2)), partialPV.getPosition());
  760.         final Vector3D acceleration = hasDerivatives() ?
  761.                                       keplerianAcceleration.add(nonKeplerianAcceleration()) :
  762.                                       keplerianAcceleration;

  763.         return new TimeStampedPVCoordinates(getDate(), partialPV.getPosition(), partialPV.getVelocity(), acceleration);

  764.     }

  765.     /** {@inheritDoc} */
  766.     @Override
  767.     public EquinoctialOrbit shiftedBy(final double dt) {

  768.         // use Keplerian-only motion
  769.         final EquinoctialOrbit keplerianShifted = new EquinoctialOrbit(a, ex, ey, hx, hy,
  770.                                                                        getLM() + getKeplerianMeanMotion() * dt,
  771.                                                                        PositionAngleType.MEAN, cachedPositionAngleType,
  772.                                                                        getFrame(),
  773.                                                                        getDate().shiftedBy(dt), getMu());

  774.         if (hasDerivatives()) {

  775.             // extract non-Keplerian acceleration from first time derivatives
  776.             final Vector3D nonKeplerianAcceleration = nonKeplerianAcceleration();

  777.             // add quadratic effect of non-Keplerian acceleration to Keplerian-only shift
  778.             keplerianShifted.computePVWithoutA();
  779.             final Vector3D fixedP   = new Vector3D(1, keplerianShifted.partialPV.getPosition(),
  780.                                                    0.5 * dt * dt, nonKeplerianAcceleration);
  781.             final double   fixedR2 = fixedP.getNormSq();
  782.             final double   fixedR  = FastMath.sqrt(fixedR2);
  783.             final Vector3D fixedV  = new Vector3D(1, keplerianShifted.partialPV.getVelocity(),
  784.                                                   dt, nonKeplerianAcceleration);
  785.             final Vector3D fixedA  = new Vector3D(-getMu() / (fixedR2 * fixedR), keplerianShifted.partialPV.getPosition(),
  786.                                                   1, nonKeplerianAcceleration);

  787.             // build a new orbit, taking non-Keplerian acceleration into account
  788.             return new EquinoctialOrbit(new TimeStampedPVCoordinates(keplerianShifted.getDate(),
  789.                                                                      fixedP, fixedV, fixedA),
  790.                                         keplerianShifted.getFrame(), keplerianShifted.getMu());

  791.         } else {
  792.             // Keplerian-only motion is all we can do
  793.             return keplerianShifted;
  794.         }

  795.     }

  796.     /** {@inheritDoc} */
  797.     @Override
  798.     protected double[][] computeJacobianMeanWrtCartesian() {

  799.         final double[][] jacobian = new double[6][6];

  800.         // compute various intermediate parameters
  801.         computePVWithoutA();
  802.         final Vector3D position = partialPV.getPosition();
  803.         final Vector3D velocity = partialPV.getVelocity();
  804.         final double r2         = position.getNormSq();
  805.         final double r          = FastMath.sqrt(r2);
  806.         final double r3         = r * r2;

  807.         final double mu         = getMu();
  808.         final double sqrtMuA    = FastMath.sqrt(a * mu);
  809.         final double a2         = a * a;

  810.         final double e2         = ex * ex + ey * ey;
  811.         final double oMe2       = 1 - e2;
  812.         final double epsilon    = FastMath.sqrt(oMe2);
  813.         final double beta       = 1 / (1 + epsilon);
  814.         final double ratio      = epsilon * beta;

  815.         final double hx2        = hx * hx;
  816.         final double hy2        = hy * hy;
  817.         final double hxhy       = hx * hy;

  818.         // precomputing equinoctial frame unit vectors (f, g, w)
  819.         final Vector3D f  = new Vector3D(1 - hy2 + hx2, 2 * hxhy, -2 * hy).normalize();
  820.         final Vector3D g  = new Vector3D(2 * hxhy, 1 + hy2 - hx2, 2 * hx).normalize();
  821.         final Vector3D w  = Vector3D.crossProduct(position, velocity).normalize();

  822.         // coordinates of the spacecraft in the equinoctial frame
  823.         final double x    = Vector3D.dotProduct(position, f);
  824.         final double y    = Vector3D.dotProduct(position, g);
  825.         final double xDot = Vector3D.dotProduct(velocity, f);
  826.         final double yDot = Vector3D.dotProduct(velocity, g);

  827.         // drDot / dEx = dXDot / dEx * f + dYDot / dEx * g
  828.         final double c1 = a / (sqrtMuA * epsilon);
  829.         final double c2 = a * sqrtMuA * beta / r3;
  830.         final double c3 = sqrtMuA / (r3 * epsilon);
  831.         final Vector3D drDotSdEx = new Vector3D( c1 * xDot * yDot - c2 * ey * x - c3 * x * y, f,
  832.                                                 -c1 * xDot * xDot - c2 * ey * y + c3 * x * x, g);

  833.         // drDot / dEy = dXDot / dEy * f + dYDot / dEy * g
  834.         final Vector3D drDotSdEy = new Vector3D( c1 * yDot * yDot + c2 * ex * x - c3 * y * y, f,
  835.                                                 -c1 * xDot * yDot + c2 * ex * y + c3 * x * y, g);

  836.         // da
  837.         final Vector3D vectorAR = new Vector3D(2 * a2 / r3, position);
  838.         final Vector3D vectorARDot = new Vector3D(2 * a2 / mu, velocity);
  839.         fillHalfRow(1, vectorAR,    jacobian[0], 0);
  840.         fillHalfRow(1, vectorARDot, jacobian[0], 3);

  841.         // dEx
  842.         final double d1 = -a * ratio / r3;
  843.         final double d2 = (hy * xDot - hx * yDot) / (sqrtMuA * epsilon);
  844.         final double d3 = (hx * y - hy * x) / sqrtMuA;
  845.         final Vector3D vectorExRDot =
  846.             new Vector3D((2 * x * yDot - xDot * y) / mu, g, -y * yDot / mu, f, -ey * d3 / epsilon, w);
  847.         fillHalfRow(ex * d1, position, -ey * d2, w, epsilon / sqrtMuA, drDotSdEy, jacobian[1], 0);
  848.         fillHalfRow(1, vectorExRDot, jacobian[1], 3);

  849.         // dEy
  850.         final Vector3D vectorEyRDot =
  851.             new Vector3D((2 * xDot * y - x * yDot) / mu, f, -x * xDot / mu, g, ex * d3 / epsilon, w);
  852.         fillHalfRow(ey * d1, position, ex * d2, w, -epsilon / sqrtMuA, drDotSdEx, jacobian[2], 0);
  853.         fillHalfRow(1, vectorEyRDot, jacobian[2], 3);

  854.         // dHx
  855.         final double h = (1 + hx2 + hy2) / (2 * sqrtMuA * epsilon);
  856.         fillHalfRow(-h * xDot, w, jacobian[3], 0);
  857.         fillHalfRow( h * x,    w, jacobian[3], 3);

  858.         // dHy
  859.         fillHalfRow(-h * yDot, w, jacobian[4], 0);
  860.         fillHalfRow( h * y,    w, jacobian[4], 3);

  861.         // dLambdaM
  862.         final double l = -ratio / sqrtMuA;
  863.         fillHalfRow(-1 / sqrtMuA, velocity, d2, w, l * ex, drDotSdEx, l * ey, drDotSdEy, jacobian[5], 0);
  864.         fillHalfRow(-2 / sqrtMuA, position, ex * beta, vectorEyRDot, -ey * beta, vectorExRDot, d3, w, jacobian[5], 3);

  865.         return jacobian;

  866.     }

  867.     /** {@inheritDoc} */
  868.     @Override
  869.     protected double[][] computeJacobianEccentricWrtCartesian() {

  870.         // start by computing the Jacobian with mean angle
  871.         final double[][] jacobian = computeJacobianMeanWrtCartesian();

  872.         // Differentiating the Kepler equation lM = lE - ex sin lE + ey cos lE leads to:
  873.         // dlM = (1 - ex cos lE - ey sin lE) dE - sin lE dex + cos lE dey
  874.         // which is inverted and rewritten as:
  875.         // dlE = a/r dlM + sin lE a/r dex - cos lE a/r dey
  876.         final SinCos scLe  = FastMath.sinCos(getLE());
  877.         final double cosLe = scLe.cos();
  878.         final double sinLe = scLe.sin();
  879.         final double aOr   = 1 / (1 - ex * cosLe - ey * sinLe);

  880.         // update longitude row
  881.         final double[] rowEx = jacobian[1];
  882.         final double[] rowEy = jacobian[2];
  883.         final double[] rowL  = jacobian[5];
  884.         for (int j = 0; j < 6; ++j) {
  885.             rowL[j] = aOr * (rowL[j] + sinLe * rowEx[j] - cosLe * rowEy[j]);
  886.         }

  887.         return jacobian;

  888.     }

  889.     /** {@inheritDoc} */
  890.     @Override
  891.     protected double[][] computeJacobianTrueWrtCartesian() {

  892.         // start by computing the Jacobian with eccentric angle
  893.         final double[][] jacobian = computeJacobianEccentricWrtCartesian();

  894.         // Differentiating the eccentric longitude equation
  895.         // tan((lv - lE)/2) = [ex sin lE - ey cos lE] / [sqrt(1-ex^2-ey^2) + 1 - ex cos lE - ey sin lE]
  896.         // leads to
  897.         // cT (dlv - dlE) = cE dlE + cX dex + cY dey
  898.         // with
  899.         // cT = [d^2 + (ex sin lE - ey cos lE)^2] / 2
  900.         // d  = 1 + sqrt(1-ex^2-ey^2) - ex cos lE - ey sin lE
  901.         // cE = (ex cos lE + ey sin lE) (sqrt(1-ex^2-ey^2) + 1) - ex^2 - ey^2
  902.         // cX =  sin lE (sqrt(1-ex^2-ey^2) + 1) - ey + ex (ex sin lE - ey cos lE) / sqrt(1-ex^2-ey^2)
  903.         // cY = -cos lE (sqrt(1-ex^2-ey^2) + 1) + ex + ey (ex sin lE - ey cos lE) / sqrt(1-ex^2-ey^2)
  904.         // which can be solved to find the differential of the true longitude
  905.         // dlv = (cT + cE) / cT dlE + cX / cT deX + cY / cT deX
  906.         final SinCos scLe      = FastMath.sinCos(getLE());
  907.         final double cosLe     = scLe.cos();
  908.         final double sinLe     = scLe.sin();
  909.         final double eSinE     = ex * sinLe - ey * cosLe;
  910.         final double ecosE     = ex * cosLe + ey * sinLe;
  911.         final double e2        = ex * ex + ey * ey;
  912.         final double epsilon   = FastMath.sqrt(1 - e2);
  913.         final double onePeps   = 1 + epsilon;
  914.         final double d         = onePeps - ecosE;
  915.         final double cT        = (d * d + eSinE * eSinE) / 2;
  916.         final double cE        = ecosE * onePeps - e2;
  917.         final double cX        = ex * eSinE / epsilon - ey + sinLe * onePeps;
  918.         final double cY        = ey * eSinE / epsilon + ex - cosLe * onePeps;
  919.         final double factorLe  = (cT + cE) / cT;
  920.         final double factorEx  = cX / cT;
  921.         final double factorEy  = cY / cT;

  922.         // update longitude row
  923.         final double[] rowEx = jacobian[1];
  924.         final double[] rowEy = jacobian[2];
  925.         final double[] rowL = jacobian[5];
  926.         for (int j = 0; j < 6; ++j) {
  927.             rowL[j] = factorLe * rowL[j] + factorEx * rowEx[j] + factorEy * rowEy[j];
  928.         }

  929.         return jacobian;

  930.     }

  931.     /** {@inheritDoc} */
  932.     @Override
  933.     public void addKeplerContribution(final PositionAngleType type, final double gm,
  934.                                       final double[] pDot) {
  935.         pDot[5] += computeKeplerianLDot(type, a, ex, ey, gm, cachedL, cachedPositionAngleType);
  936.     }

  937.     /**
  938.      * Compute rate of argument of longitude.
  939.      * @param type position angle type of rate
  940.      * @param a semi major axis
  941.      * @param ex ex
  942.      * @param ey ey
  943.      * @param mu mu
  944.      * @param l argument of longitude
  945.      * @param cachedType position angle type of passed l
  946.      * @return first-order time derivative for l
  947.      * @since 12.2
  948.      */
  949.     private static double computeKeplerianLDot(final PositionAngleType type, final double a, final double ex,
  950.                                                final double ey, final double mu,
  951.                                                final double l, final PositionAngleType cachedType) {
  952.         final double n  = FastMath.sqrt(mu / a) / a;
  953.         if (type == PositionAngleType.MEAN) {
  954.             return n;
  955.         }
  956.         final double oMe2;
  957.         final double ksi;
  958.         final SinCos sc;
  959.         if (type == PositionAngleType.ECCENTRIC) {
  960.             sc = FastMath.sinCos(EquinoctialLongitudeArgumentUtility.convertL(cachedType, l, ex, ey, type));
  961.             ksi  = 1. / (1 - ex * sc.cos() - ey * sc.sin());
  962.             return n * ksi;
  963.         } else { // TRUE
  964.             sc = FastMath.sinCos(EquinoctialLongitudeArgumentUtility.convertL(cachedType, l, ex, ey, type));
  965.             oMe2 = 1 - ex * ex - ey * ey;
  966.             ksi  = 1 + ex * sc.cos() + ey * sc.sin();
  967.             return n * ksi * ksi / (oMe2 * FastMath.sqrt(oMe2));
  968.         }
  969.     }

  970.     /**  Returns a string representation of this equinoctial parameters object.
  971.      * @return a string representation of this object
  972.      */
  973.     public String toString() {
  974.         return new StringBuilder().append("equinoctial parameters: ").append('{').
  975.                                   append("a: ").append(a).
  976.                                   append("; ex: ").append(ex).append("; ey: ").append(ey).
  977.                                   append("; hx: ").append(hx).append("; hy: ").append(hy).
  978.                                   append("; lv: ").append(FastMath.toDegrees(getLv())).
  979.                                   append(";}").toString();
  980.     }

  981.     /** {@inheritDoc} */
  982.     @Override
  983.     public PositionAngleType getCachedPositionAngleType() {
  984.         return cachedPositionAngleType;
  985.     }

  986.     /** {@inheritDoc} */
  987.     @Override
  988.     public boolean hasRates() {
  989.         return hasDerivatives();
  990.     }

  991.     /** {@inheritDoc} */
  992.     @Override
  993.     public EquinoctialOrbit removeRates() {
  994.         final PositionAngleType positionAngleType = getCachedPositionAngleType();
  995.         return new EquinoctialOrbit(getA(), getEquinoctialEx(), getEquinoctialEy(), getHx(), getHy(),
  996.                 getL(positionAngleType), positionAngleType, getFrame(), getDate(), getMu());
  997.     }

  998.     /** Replace the instance with a data transfer object for serialization.
  999.      * @return data transfer object that will be serialized
  1000.      */
  1001.     @DefaultDataContext
  1002.     private Object writeReplace() {
  1003.         return new DTO(this);
  1004.     }

  1005.     /** Internal class used only for serialization. */
  1006.     @DefaultDataContext
  1007.     private static class DTO implements Serializable {

  1008.         /** Serializable UID. */
  1009.         private static final long serialVersionUID = 20231217L;

  1010.         /** Double values. */
  1011.         private final double[] d;

  1012.         /** Frame in which are defined the orbital parameters. */
  1013.         private final Frame frame;

  1014.         /** Cached type of position angle. */
  1015.         private final PositionAngleType positionAngleType;

  1016.         /** Simple constructor.
  1017.          * @param orbit instance to serialize
  1018.          */
  1019.         private DTO(final EquinoctialOrbit orbit) {

  1020.             final TimeStampedPVCoordinates pv = orbit.getPVCoordinates();
  1021.             positionAngleType = orbit.cachedPositionAngleType;

  1022.             // decompose date
  1023.             final AbsoluteDate j2000Epoch =
  1024.                     DataContext.getDefault().getTimeScales().getJ2000Epoch();
  1025.             final double epoch  = FastMath.floor(pv.getDate().durationFrom(j2000Epoch));
  1026.             final double offset = pv.getDate().durationFrom(j2000Epoch.shiftedBy(epoch));

  1027.             if (orbit.hasDerivatives()) {
  1028.                 // we have derivatives
  1029.                 this.d = new double[] {
  1030.                     epoch, offset, orbit.getMu(),
  1031.                     orbit.a, orbit.ex, orbit.ey,
  1032.                     orbit.hx, orbit.hy, orbit.cachedL,
  1033.                     orbit.aDot, orbit.exDot, orbit.eyDot,
  1034.                     orbit.hxDot, orbit.hyDot, orbit.cachedLDot
  1035.                 };
  1036.             } else {
  1037.                 // we don't have derivatives
  1038.                 this.d = new double[] {
  1039.                     epoch, offset, orbit.getMu(),
  1040.                     orbit.a, orbit.ex, orbit.ey,
  1041.                     orbit.hx, orbit.hy, orbit.cachedL
  1042.                 };
  1043.             }

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

  1045.         }

  1046.         /** Replace the deserialized data transfer object with a {@link EquinoctialOrbit}.
  1047.          * @return replacement {@link EquinoctialOrbit}
  1048.          */
  1049.         private Object readResolve() {
  1050.             final AbsoluteDate j2000Epoch =
  1051.                     DataContext.getDefault().getTimeScales().getJ2000Epoch();
  1052.             if (d.length >= 15) {
  1053.                 // we have derivatives
  1054.                 return new EquinoctialOrbit(d[ 3], d[ 4], d[ 5], d[ 6], d[ 7], d[ 8],
  1055.                                             d[ 9], d[10], d[11], d[12], d[13], d[14],
  1056.                                             positionAngleType,
  1057.                                             frame, j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
  1058.                                             d[2]);
  1059.             } else {
  1060.                 // we don't have derivatives
  1061.                 return new EquinoctialOrbit(d[ 3], d[ 4], d[ 5], d[ 6], d[ 7], d[ 8], positionAngleType,
  1062.                                             frame, j2000Epoch.shiftedBy(d[0]).shiftedBy(d[1]),
  1063.                                             d[2]);
  1064.             }
  1065.         }

  1066.     }

  1067. }