CircularOrbit.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.orbits;

  18. import org.hipparchus.analysis.differentiation.UnivariateDerivative1;
  19. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  20. import org.hipparchus.util.FastMath;
  21. import org.hipparchus.util.SinCos;
  22. import org.orekit.errors.OrekitIllegalArgumentException;
  23. import org.orekit.errors.OrekitInternalError;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.frames.KinematicTransform;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.time.TimeOffset;
  29. import org.orekit.utils.PVCoordinates;
  30. import org.orekit.utils.TimeStampedPVCoordinates;


  31. /**
  32.  * This class handles circular orbital parameters.

  33.  * <p>
  34.  * The parameters used internally are the circular elements which can be
  35.  * related to Keplerian elements as follows:
  36.  *   <ul>
  37.  *     <li>a</li>
  38.  *     <li>e<sub>x</sub> = e cos(ω)</li>
  39.  *     <li>e<sub>y</sub> = e sin(ω)</li>
  40.  *     <li>i</li>
  41.  *     <li>Ω</li>
  42.  *     <li>α<sub>v</sub> = v + ω</li>
  43.  *   </ul>
  44.  * where Ω stands for the Right Ascension of the Ascending Node and
  45.  * α<sub>v</sub> stands for the true latitude argument
  46.  *
  47.  * <p>
  48.  * The conversion equations from and to Keplerian elements given above hold only
  49.  * when both sides are unambiguously defined, i.e. when orbit is neither equatorial
  50.  * nor circular. When orbit is circular (but not equatorial), the circular
  51.  * parameters are still unambiguously defined whereas some Keplerian elements
  52.  * (more precisely ω and Ω) become ambiguous. When orbit is equatorial,
  53.  * neither the Keplerian nor the circular parameters can be defined unambiguously.
  54.  * {@link EquinoctialOrbit equinoctial orbits} is the recommended way to represent
  55.  * orbits.
  56.  * </p>
  57.  * <p>
  58.  * The instance <code>CircularOrbit</code> is guaranteed to be immutable.
  59.  * </p>
  60.  * @see    Orbit
  61.  * @see    KeplerianOrbit
  62.  * @see    CartesianOrbit
  63.  * @see    EquinoctialOrbit
  64.  * @author Luc Maisonobe
  65.  * @author Fabien Maussion
  66.  * @author V&eacute;ronique Pommier-Maurussane
  67.  */

  68. public class CircularOrbit extends Orbit implements PositionAngleBased<CircularOrbit> {

  69.     /** Semi-major axis (m). */
  70.     private final double a;

  71.     /** First component of the circular eccentricity vector. */
  72.     private final double ex;

  73.     /** Second component of the circular eccentricity vector. */
  74.     private final double ey;

  75.     /** Inclination (rad). */
  76.     private final double i;

  77.     /** Right Ascension of Ascending Node (rad). */
  78.     private final double raan;

  79.     /** Cached latitude argument (rad). */
  80.     private final double cachedAlpha;

  81.     /** Type of cached position angle (latitude argument). */
  82.     private final PositionAngleType cachedPositionAngleType;

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

  85.     /** First component of the circular eccentricity vector derivative. */
  86.     private final double exDot;

  87.     /** Second component of the circular eccentricity vector derivative. */
  88.     private final double eyDot;

  89.     /** Inclination derivative (rad/s). */
  90.     private final double iDot;

  91.     /** Right Ascension of Ascending Node derivative (rad/s). */
  92.     private final double raanDot;

  93.     /** True latitude argument derivative (rad/s). */
  94.     private final double cachedAlphaDot;

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

  97.     /** Creates a new instance.
  98.      * @param a  semi-major axis (m)
  99.      * @param ex e cos(ω), first component of circular eccentricity vector
  100.      * @param ey e sin(ω), second component of circular eccentricity vector
  101.      * @param i inclination (rad)
  102.      * @param raan right ascension of ascending node (Ω, rad)
  103.      * @param alpha  an + ω, mean, eccentric or true latitude argument (rad)
  104.      * @param type type of latitude argument
  105.      * @param cachedPositionAngleType type of cached latitude argument
  106.      * @param frame the frame in which are defined the parameters
  107.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  108.      * @param date date of the orbital parameters
  109.      * @param mu central attraction coefficient (m³/s²)
  110.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  111.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  112.      * @since 12.1
  113.      */
  114.     public CircularOrbit(final double a, final double ex, final double ey,
  115.                          final double i, final double raan, final double alpha,
  116.                          final PositionAngleType type, final PositionAngleType cachedPositionAngleType,
  117.                          final Frame frame, final AbsoluteDate date, final double mu)
  118.         throws IllegalArgumentException {
  119.         this(a, ex, ey, i, raan, alpha, 0., 0., 0., 0., 0.,
  120.             computeKeplerianAlphaDot(type, a, ex, ey, mu, alpha, type),
  121.             type, cachedPositionAngleType, frame, date, mu);
  122.     }

  123.     /** Creates a new instance without derivatives and with cached position angle same as value inputted.
  124.      * @param a  semi-major axis (m)
  125.      * @param ex e cos(ω), first component of circular eccentricity vector
  126.      * @param ey e sin(ω), second component of circular eccentricity vector
  127.      * @param i inclination (rad)
  128.      * @param raan right ascension of ascending node (Ω, rad)
  129.      * @param alpha  an + ω, mean, eccentric or true latitude argument (rad)
  130.      * @param type type of latitude argument
  131.      * @param frame the frame in which are defined the parameters
  132.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  133.      * @param date date of the orbital parameters
  134.      * @param mu central attraction coefficient (m³/s²)
  135.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  136.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  137.      */
  138.     public CircularOrbit(final double a, final double ex, final double ey,
  139.                          final double i, final double raan, final double alpha,
  140.                          final PositionAngleType type,
  141.                          final Frame frame, final AbsoluteDate date, final double mu)
  142.             throws IllegalArgumentException {
  143.         this(a, ex, ey, i, raan, alpha, type, type, frame, date, mu);
  144.     }

  145.     /** Creates a new instance.
  146.      * @param a  semi-major axis (m)
  147.      * @param ex e cos(ω), first component of circular eccentricity vector
  148.      * @param ey e sin(ω), second component of circular eccentricity vector
  149.      * @param i inclination (rad)
  150.      * @param raan right ascension of ascending node (Ω, rad)
  151.      * @param alpha  an + ω, mean, eccentric or true latitude argument (rad)
  152.      * @param aDot  semi-major axis derivative (m/s)
  153.      * @param exDot d(e cos(ω))/dt, first component of circular eccentricity vector derivative
  154.      * @param eyDot d(e sin(ω))/dt, second component of circular eccentricity vector derivative
  155.      * @param iDot inclination  derivative(rad/s)
  156.      * @param raanDot right ascension of ascending node derivative (rad/s)
  157.      * @param alphaDot  d(an + ω), mean, eccentric or true latitude argument derivative (rad/s)
  158.      * @param type type of latitude argument
  159.      * @param cachedPositionAngleType type of cached latitude argument
  160.      * @param frame the frame in which are defined the parameters
  161.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  162.      * @param date date of the orbital parameters
  163.      * @param mu central attraction coefficient (m³/s²)
  164.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  165.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  166.      * @since 12.1
  167.      */
  168.     public CircularOrbit(final double a, final double ex, final double ey,
  169.                          final double i, final double raan, final double alpha,
  170.                          final double aDot, final double exDot, final double eyDot,
  171.                          final double iDot, final double raanDot, final double alphaDot,
  172.                          final PositionAngleType type, final PositionAngleType cachedPositionAngleType,
  173.                          final Frame frame, final AbsoluteDate date, final double mu)
  174.         throws IllegalArgumentException {
  175.         super(frame, date, mu);
  176.         if (ex * ex + ey * ey >= 1.0) {
  177.             throw new OrekitIllegalArgumentException(OrekitMessages.HYPERBOLIC_ORBIT_NOT_HANDLED_AS,
  178.                                                      getClass().getName());
  179.         }
  180.         this.a       =  a;
  181.         this.aDot    =  aDot;
  182.         this.ex      = ex;
  183.         this.exDot   = exDot;
  184.         this.ey      = ey;
  185.         this.eyDot   = eyDot;
  186.         this.i       = i;
  187.         this.iDot    = iDot;
  188.         this.raan    = raan;
  189.         this.raanDot = raanDot;
  190.         this.cachedPositionAngleType = cachedPositionAngleType;

  191.         final UnivariateDerivative1 alphaUD = initializeCachedAlpha(alpha, alphaDot, type);
  192.         this.cachedAlpha = alphaUD.getValue();
  193.         this.cachedAlphaDot = alphaUD.getFirstDerivative();

  194.         partialPV   = null;

  195.     }

  196.     /** Creates a new instance with derivatives and with cached position angle same as value inputted.
  197.      * @param a  semi-major axis (m)
  198.      * @param ex e cos(ω), first component of circular eccentricity vector
  199.      * @param ey e sin(ω), second component of circular eccentricity vector
  200.      * @param i inclination (rad)
  201.      * @param raan right ascension of ascending node (Ω, rad)
  202.      * @param alpha  an + ω, mean, eccentric or true latitude argument (rad)
  203.      * @param aDot  semi-major axis derivative (m/s)
  204.      * @param exDot d(e cos(ω))/dt, first component of circular eccentricity vector derivative
  205.      * @param eyDot d(e sin(ω))/dt, second component of circular eccentricity vector derivative
  206.      * @param iDot inclination  derivative(rad/s)
  207.      * @param raanDot right ascension of ascending node derivative (rad/s)
  208.      * @param alphaDot  d(an + ω), mean, eccentric or true latitude argument derivative (rad/s)
  209.      * @param type type of latitude argument
  210.      * @param frame the frame in which are defined the parameters
  211.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  212.      * @param date date of the orbital parameters
  213.      * @param mu central attraction coefficient (m³/s²)
  214.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  215.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  216.      */
  217.     public CircularOrbit(final double a, final double ex, final double ey,
  218.                          final double i, final double raan, final double alpha,
  219.                          final double aDot, final double exDot, final double eyDot,
  220.                          final double iDot, final double raanDot, final double alphaDot,
  221.                          final PositionAngleType type,
  222.                          final Frame frame, final AbsoluteDate date, final double mu)
  223.             throws IllegalArgumentException {
  224.         this(a, ex, ey, i, raan, alpha, aDot, exDot, eyDot, iDot, raanDot, alphaDot, type, type,
  225.                 frame, date, mu);
  226.     }

  227.     /** Creates a new instance.
  228.      * @param a  semi-major axis (m)
  229.      * @param ex e cos(ω), first component of circular eccentricity vector
  230.      * @param ey e sin(ω), second component of circular eccentricity vector
  231.      * @param i inclination (rad)
  232.      * @param raan right ascension of ascending node (Ω, rad)
  233.      * @param alpha  input latitude argument (rad)
  234.      * @param aDot  semi-major axis derivative (m/s)
  235.      * @param exDot d(e cos(ω))/dt, first component of circular eccentricity vector derivative
  236.      * @param eyDot d(e sin(ω))/dt, second component of circular eccentricity vector derivative
  237.      * @param iDot inclination  derivative(rad/s)
  238.      * @param raanDot right ascension of ascending node derivative (rad/s)
  239.      * @param alphaDot  input latitude argument derivative (rad/s)
  240.      * @param pvCoordinates the {@link PVCoordinates} in inertial frame
  241.      * @param positionAngleType type of position angle
  242.      * @param frame the frame in which are defined the parameters
  243.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  244.      * @param mu central attraction coefficient (m³/s²)
  245.      * @exception IllegalArgumentException if eccentricity is equal to 1 or larger or
  246.      * if frame is not a {@link Frame#isPseudoInertial pseudo-inertial frame}
  247.      */
  248.     private CircularOrbit(final double a, final double ex, final double ey,
  249.                           final double i, final double raan, final double alpha,
  250.                           final double aDot, final double exDot, final double eyDot,
  251.                           final double iDot, final double raanDot, final double alphaDot,
  252.                           final TimeStampedPVCoordinates pvCoordinates,
  253.                           final PositionAngleType positionAngleType, final Frame frame, final double mu)
  254.         throws IllegalArgumentException {
  255.         super(pvCoordinates, frame, mu);
  256.         this.a           =  a;
  257.         this.aDot        =  aDot;
  258.         this.ex          = ex;
  259.         this.exDot       = exDot;
  260.         this.ey          = ey;
  261.         this.eyDot       = eyDot;
  262.         this.i           = i;
  263.         this.iDot        = iDot;
  264.         this.raan        = raan;
  265.         this.raanDot     = raanDot;
  266.         this.cachedAlpha = alpha;
  267.         this.cachedAlphaDot = alphaDot;
  268.         this.cachedPositionAngleType = positionAngleType;
  269.         this.partialPV   = null;
  270.     }

  271.     /** Constructor from Cartesian parameters.
  272.      *
  273.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  274.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  275.      * use {@code mu} and the position to compute the acceleration, including
  276.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  277.      *
  278.      * @param pvCoordinates the {@link PVCoordinates} in inertial frame
  279.      * @param frame the frame in which are defined the {@link PVCoordinates}
  280.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  281.      * @param mu central attraction coefficient (m³/s²)
  282.      * @exception IllegalArgumentException if frame is not a {@link
  283.      * Frame#isPseudoInertial pseudo-inertial frame}
  284.      */
  285.     public CircularOrbit(final TimeStampedPVCoordinates pvCoordinates, final Frame frame, final double mu)
  286.         throws IllegalArgumentException {
  287.         super(pvCoordinates, frame, mu);
  288.         this.cachedPositionAngleType = PositionAngleType.TRUE;

  289.         // compute semi-major axis
  290.         final Vector3D pvP = pvCoordinates.getPosition();
  291.         final Vector3D pvV = pvCoordinates.getVelocity();
  292.         final Vector3D pvA = pvCoordinates.getAcceleration();
  293.         final double r2 = pvP.getNormSq();
  294.         final double r  = FastMath.sqrt(r2);
  295.         final double V2 = pvV.getNormSq();
  296.         final double rV2OnMu = r * V2 / mu;
  297.         a = r / (2 - rV2OnMu);

  298.         if (!isElliptical()) {
  299.             throw new OrekitIllegalArgumentException(OrekitMessages.HYPERBOLIC_ORBIT_NOT_HANDLED_AS,
  300.                                                      getClass().getName());
  301.         }

  302.         // compute inclination
  303.         final Vector3D momentum = pvCoordinates.getMomentum();
  304.         i = Vector3D.angle(momentum, Vector3D.PLUS_K);

  305.         // compute right ascension of ascending node
  306.         final Vector3D node  = Vector3D.crossProduct(Vector3D.PLUS_K, momentum);
  307.         raan = FastMath.atan2(node.getY(), node.getX());

  308.         // 2D-coordinates in the canonical frame
  309.         final SinCos scRaan = FastMath.sinCos(raan);
  310.         final SinCos scI    = FastMath.sinCos(i);
  311.         final double xP     = pvP.getX();
  312.         final double yP     = pvP.getY();
  313.         final double zP     = pvP.getZ();
  314.         final double x2     = (xP * scRaan.cos() + yP * scRaan.sin()) / a;
  315.         final double y2     = ((yP * scRaan.cos() - xP * scRaan.sin()) * scI.cos() + zP * scI.sin()) / a;

  316.         // compute eccentricity vector
  317.         final double eSE    = Vector3D.dotProduct(pvP, pvV) / FastMath.sqrt(mu * a);
  318.         final double eCE    = rV2OnMu - 1;
  319.         final double e2     = eCE * eCE + eSE * eSE;
  320.         final double f      = eCE - e2;
  321.         final double g      = FastMath.sqrt(1 - e2) * eSE;
  322.         final double aOnR   = a / r;
  323.         final double a2OnR2 = aOnR * aOnR;
  324.         ex = a2OnR2 * (f * x2 + g * y2);
  325.         ey = a2OnR2 * (f * y2 - g * x2);

  326.         // compute latitude argument
  327.         final double beta = 1 / (1 + FastMath.sqrt(1 - ex * ex - ey * ey));
  328.         cachedAlpha = CircularLatitudeArgumentUtility.eccentricToTrue(ex, ey, FastMath.atan2(y2 + ey + eSE * beta * ex, x2 + ex - eSE * beta * ey));

  329.         partialPV   = pvCoordinates;

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

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

  334.             final Vector3D keplerianAcceleration    = new Vector3D(-mu / (r * r2), pvP);
  335.             final Vector3D nonKeplerianAcceleration = pvA.subtract(keplerianAcceleration);
  336.             final double   aX                       = nonKeplerianAcceleration.getX();
  337.             final double   aY                       = nonKeplerianAcceleration.getY();
  338.             final double   aZ                       = nonKeplerianAcceleration.getZ();
  339.             aDot    = jacobian[0][3] * aX + jacobian[0][4] * aY + jacobian[0][5] * aZ;
  340.             exDot   = jacobian[1][3] * aX + jacobian[1][4] * aY + jacobian[1][5] * aZ;
  341.             eyDot   = jacobian[2][3] * aX + jacobian[2][4] * aY + jacobian[2][5] * aZ;
  342.             iDot    = jacobian[3][3] * aX + jacobian[3][4] * aY + jacobian[3][5] * aZ;
  343.             raanDot = jacobian[4][3] * aX + jacobian[4][4] * aY + jacobian[4][5] * aZ;

  344.             // in order to compute latitude argument derivative, we must compute
  345.             // mean latitude argument derivative including Keplerian motion and convert to true latitude argument
  346.             final double alphaMDot = getKeplerianMeanMotion() +
  347.                                      jacobian[5][3] * aX + jacobian[5][4] * aY + jacobian[5][5] * aZ;
  348.             final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex, exDot);
  349.             final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey, eyDot);
  350.             final UnivariateDerivative1 alphaMUD = new UnivariateDerivative1(getAlphaM(), alphaMDot);
  351.             final UnivariateDerivative1 alphavUD = FieldCircularLatitudeArgumentUtility.meanToTrue(exUD, eyUD, alphaMUD);
  352.             cachedAlphaDot = alphavUD.getFirstDerivative();

  353.         } else {
  354.             // acceleration is either almost zero or NaN,
  355.             // we assume acceleration was not known
  356.             // we don't set up derivatives
  357.             aDot      = 0.;
  358.             exDot     = 0.;
  359.             eyDot     = 0.;
  360.             iDot      = 0.;
  361.             raanDot   = 0.;
  362.             cachedAlphaDot = computeKeplerianAlphaDot(cachedPositionAngleType, a, ex, ey, mu, cachedAlpha, cachedPositionAngleType);
  363.         }

  364.     }

  365.     /** Constructor from Cartesian parameters.
  366.      *
  367.      * <p> The acceleration provided in {@code pvCoordinates} is accessible using
  368.      * {@link #getPVCoordinates()} and {@link #getPVCoordinates(Frame)}. All other methods
  369.      * use {@code mu} and the position to compute the acceleration, including
  370.      * {@link #shiftedBy(double)} and {@link #getPVCoordinates(AbsoluteDate, Frame)}.
  371.      *
  372.      * @param pvCoordinates the {@link PVCoordinates} in inertial frame
  373.      * @param frame the frame in which are defined the {@link PVCoordinates}
  374.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  375.      * @param date date of the orbital parameters
  376.      * @param mu central attraction coefficient (m³/s²)
  377.      * @exception IllegalArgumentException if frame is not a {@link
  378.      * Frame#isPseudoInertial pseudo-inertial frame}
  379.      */
  380.     public CircularOrbit(final PVCoordinates pvCoordinates, final Frame frame,
  381.                          final AbsoluteDate date, final double mu)
  382.         throws IllegalArgumentException {
  383.         this(new TimeStampedPVCoordinates(date, pvCoordinates), frame, mu);
  384.     }

  385.     /** Constructor from any kind of orbital parameters.
  386.      * @param op orbital parameters to copy
  387.      */
  388.     public CircularOrbit(final Orbit op) {

  389.         super(op.getFrame(), op.getDate(), op.getMu());

  390.         a    = op.getA();
  391.         i    = op.getI();
  392.         final double hx = op.getHx();
  393.         final double hy = op.getHy();
  394.         final double h2 = hx * hx + hy * hy;
  395.         final double h  = FastMath.sqrt(h2);
  396.         raan = FastMath.atan2(hy, hx);
  397.         final SinCos scRaan  = FastMath.sinCos(raan);
  398.         final double cosRaan = h == 0 ? scRaan.cos() : hx / h;
  399.         final double sinRaan = h == 0 ? scRaan.sin() : hy / h;
  400.         final double equiEx = op.getEquinoctialEx();
  401.         final double equiEy = op.getEquinoctialEy();
  402.         ex     = equiEx * cosRaan + equiEy * sinRaan;
  403.         ey     = equiEy * cosRaan - equiEx * sinRaan;
  404.         cachedPositionAngleType = PositionAngleType.TRUE;
  405.         cachedAlpha = op.getLv() - raan;

  406.         if (op.hasNonKeplerianAcceleration()) {
  407.             aDot    = op.getADot();
  408.             final double hxDot = op.getHxDot();
  409.             final double hyDot = op.getHyDot();
  410.             iDot    = 2 * (cosRaan * hxDot + sinRaan * hyDot) / (1 + h2);
  411.             raanDot = (hx * hyDot - hy * hxDot) / h2;
  412.             final double equiExDot = op.getEquinoctialExDot();
  413.             final double equiEyDot = op.getEquinoctialEyDot();
  414.             exDot   = (equiExDot + equiEy * raanDot) * cosRaan +
  415.                       (equiEyDot - equiEx * raanDot) * sinRaan;
  416.             eyDot   = (equiEyDot - equiEx * raanDot) * cosRaan -
  417.                       (equiExDot + equiEy * raanDot) * sinRaan;
  418.             cachedAlphaDot = op.getLvDot() - raanDot;
  419.         } else {
  420.             aDot      = 0.;
  421.             exDot     = 0.;
  422.             eyDot     = 0.;
  423.             iDot      = 0.;
  424.             raanDot   = 0.;
  425.             cachedAlphaDot = computeKeplerianAlphaDot(cachedPositionAngleType, a, ex, ey, getMu(), cachedAlpha, cachedPositionAngleType);
  426.         }

  427.         partialPV   = null;

  428.     }

  429.     /** {@inheritDoc} */
  430.     @Override
  431.     public boolean hasNonKeplerianAcceleration() {
  432.         return aDot != 0. || exDot != 0. || eyDot != 0. || iDot != 0. || raanDot != 0. ||
  433.                 FastMath.abs(cachedAlphaDot - computeKeplerianAlphaDot(cachedPositionAngleType, a, ex, ey, getMu(), cachedAlpha, cachedPositionAngleType)) > TOLERANCE_POSITION_ANGLE_RATE;
  434.     }

  435.     /** {@inheritDoc} */
  436.     @Override
  437.     public OrbitType getType() {
  438.         return OrbitType.CIRCULAR;
  439.     }

  440.     /** {@inheritDoc} */
  441.     @Override
  442.     public double getA() {
  443.         return a;
  444.     }

  445.     /** {@inheritDoc} */
  446.     @Override
  447.     public double getADot() {
  448.         return aDot;
  449.     }

  450.     /** {@inheritDoc} */
  451.     @Override
  452.     public double getEquinoctialEx() {
  453.         final SinCos sc = FastMath.sinCos(raan);
  454.         return ex * sc.cos() - ey * sc.sin();
  455.     }

  456.     /** {@inheritDoc} */
  457.     @Override
  458.     public double getEquinoctialExDot() {
  459.         if (!hasNonKeplerianAcceleration()) {
  460.             return 0.;
  461.         }
  462.         final SinCos sc = FastMath.sinCos(raan);
  463.         return (exDot - ey * raanDot) * sc.cos() - (eyDot + ex * raanDot) * sc.sin();
  464.     }

  465.     /** {@inheritDoc} */
  466.     @Override
  467.     public double getEquinoctialEy() {
  468.         final SinCos sc = FastMath.sinCos(raan);
  469.         return ey * sc.cos() + ex * sc.sin();
  470.     }

  471.     /** {@inheritDoc} */
  472.     @Override
  473.     public double getEquinoctialEyDot() {
  474.         if (!hasNonKeplerianAcceleration()) {
  475.             return 0.;
  476.         }
  477.         final SinCos sc = FastMath.sinCos(raan);
  478.         return (eyDot + ex * raanDot) * sc.cos() + (exDot - ey * raanDot) * sc.sin();
  479.     }

  480.     /** Get the first component of the circular eccentricity vector.
  481.      * @return ex = e cos(ω), first component of the circular eccentricity vector
  482.      */
  483.     public double getCircularEx() {
  484.         return ex;
  485.     }

  486.     /** Get the first component of the circular eccentricity vector derivative.
  487.      * @return ex = e cos(ω), first component of the circular eccentricity vector derivative
  488.      * @since 9.0
  489.      */
  490.     public double getCircularExDot() {
  491.         return exDot;
  492.     }

  493.     /** Get the second component of the circular eccentricity vector.
  494.      * @return ey = e sin(ω), second component of the circular eccentricity vector
  495.      */
  496.     public double getCircularEy() {
  497.         return ey;
  498.     }

  499.     /** Get the second component of the circular eccentricity vector derivative.
  500.      * @return ey = e sin(ω), second component of the circular eccentricity vector derivative
  501.      */
  502.     public double getCircularEyDot() {
  503.         return eyDot;
  504.     }

  505.     /** {@inheritDoc} */
  506.     @Override
  507.     public double getHx() {
  508.         // Check for equatorial retrograde orbit
  509.         if (FastMath.abs(i - FastMath.PI) < 1.0e-10) {
  510.             return Double.NaN;
  511.         }
  512.         return FastMath.cos(raan) * FastMath.tan(i / 2);
  513.     }

  514.     /** {@inheritDoc} */
  515.     @Override
  516.     public double getHxDot() {
  517.         // Check for equatorial retrograde orbit
  518.         if (FastMath.abs(i - FastMath.PI) < 1.0e-10) {
  519.             return Double.NaN;
  520.         }
  521.         if (!hasNonKeplerianAcceleration()) {
  522.             return 0.;
  523.         }
  524.         final SinCos sc  = FastMath.sinCos(raan);
  525.         final double tan = FastMath.tan(0.5 * i);
  526.         return 0.5 * sc.cos() * (1 + tan * tan) * iDot - sc.sin() * tan * raanDot;
  527.     }

  528.     /** {@inheritDoc} */
  529.     @Override
  530.     public double getHy() {
  531.         // Check for equatorial retrograde orbit
  532.         if (FastMath.abs(i - FastMath.PI) < 1.0e-10) {
  533.             return Double.NaN;
  534.         }
  535.         return FastMath.sin(raan) * FastMath.tan(i / 2);
  536.     }

  537.     /** {@inheritDoc} */
  538.     @Override
  539.     public double getHyDot() {
  540.         // Check for equatorial retrograde orbit
  541.         if (FastMath.abs(i - FastMath.PI) < 1.0e-10) {
  542.             return Double.NaN;
  543.         }
  544.         if (!hasNonKeplerianAcceleration()) {
  545.             return 0.;
  546.         }
  547.         final SinCos sc  = FastMath.sinCos(raan);
  548.         final double tan = FastMath.tan(0.5 * i);
  549.         return 0.5 * sc.sin() * (1 + tan * tan) * iDot + sc.cos() * tan * raanDot;
  550.     }

  551.     /** Get the true latitude argument.
  552.      * @return v + ω true latitude argument (rad)
  553.      */
  554.     public double getAlphaV() {
  555.         switch (cachedPositionAngleType) {
  556.             case TRUE:
  557.                 return cachedAlpha;

  558.             case ECCENTRIC:
  559.                 return CircularLatitudeArgumentUtility.eccentricToTrue(ex, ey, cachedAlpha);

  560.             case MEAN:
  561.                 return CircularLatitudeArgumentUtility.meanToTrue(ex, ey, cachedAlpha);

  562.             default:
  563.                 throw new OrekitInternalError(null);
  564.         }
  565.     }

  566.     /** Get the true latitude argument derivative.
  567.      * <p>
  568.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  569.      * </p>
  570.      * @return v + ω true latitude argument derivative (rad/s)
  571.      * @since 9.0
  572.      */
  573.     public double getAlphaVDot() {
  574.         switch (cachedPositionAngleType) {
  575.             case ECCENTRIC:
  576.                 final UnivariateDerivative1 alphaEUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  577.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  578.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  579.                 final UnivariateDerivative1 alphaVUD = FieldCircularLatitudeArgumentUtility.eccentricToTrue(exUD, eyUD,
  580.                         alphaEUD);
  581.                 return alphaVUD.getFirstDerivative();

  582.             case TRUE:
  583.                 return cachedAlphaDot;

  584.             case MEAN:
  585.                 final UnivariateDerivative1 alphaMUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  586.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  587.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  588.                 final UnivariateDerivative1 alphaVUD2 = FieldCircularLatitudeArgumentUtility.meanToTrue(exUD2,
  589.                         eyUD2, alphaMUD);
  590.                 return alphaVUD2.getFirstDerivative();

  591.             default:
  592.                 throw new OrekitInternalError(null);
  593.         }
  594.     }

  595.     /** Get the eccentric latitude argument.
  596.      * @return E + ω eccentric latitude argument (rad)
  597.      */
  598.     public double getAlphaE() {
  599.         switch (cachedPositionAngleType) {
  600.             case TRUE:
  601.                 return CircularLatitudeArgumentUtility.trueToEccentric(ex, ey, cachedAlpha);

  602.             case ECCENTRIC:
  603.                 return cachedAlpha;

  604.             case MEAN:
  605.                 return CircularLatitudeArgumentUtility.meanToEccentric(ex, ey, cachedAlpha);

  606.             default:
  607.                 throw new OrekitInternalError(null);
  608.         }
  609.     }

  610.     /** Get the eccentric latitude argument derivative.
  611.      * <p>
  612.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  613.      * </p>
  614.      * @return d(E + ω)/dt eccentric latitude argument derivative (rad/s)
  615.      * @since 9.0
  616.      */
  617.     public double getAlphaEDot() {
  618.         switch (cachedPositionAngleType) {
  619.             case TRUE:
  620.                 final UnivariateDerivative1 alphaVUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  621.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  622.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  623.                 final UnivariateDerivative1 alphaEUD = FieldCircularLatitudeArgumentUtility.trueToEccentric(exUD, eyUD,
  624.                         alphaVUD);
  625.                 return alphaEUD.getFirstDerivative();

  626.             case ECCENTRIC:
  627.                 return cachedAlphaDot;

  628.             case MEAN:
  629.                 final UnivariateDerivative1 alphaMUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  630.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  631.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  632.                 final UnivariateDerivative1 alphaVUD2 = FieldCircularLatitudeArgumentUtility.meanToEccentric(exUD2,
  633.                         eyUD2, alphaMUD);
  634.                 return alphaVUD2.getFirstDerivative();

  635.             default:
  636.                 throw new OrekitInternalError(null);
  637.         }
  638.     }

  639.     /** Get the mean latitude argument.
  640.      * @return M + ω mean latitude argument (rad)
  641.      */
  642.     public double getAlphaM() {
  643.         switch (cachedPositionAngleType) {
  644.             case TRUE:
  645.                 return CircularLatitudeArgumentUtility.trueToMean(ex, ey, cachedAlpha);

  646.             case MEAN:
  647.                 return cachedAlpha;

  648.             case ECCENTRIC:
  649.                 return CircularLatitudeArgumentUtility.eccentricToMean(ex, ey, cachedAlpha);

  650.             default:
  651.                 throw new OrekitInternalError(null);
  652.         }
  653.     }

  654.     /** Get the mean latitude argument derivative.
  655.      * <p>
  656.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  657.      * </p>
  658.      * @return d(M + ω)/dt mean latitude argument derivative (rad/s)
  659.      * @since 9.0
  660.      */
  661.     public double getAlphaMDot() {
  662.         switch (cachedPositionAngleType) {
  663.             case TRUE:
  664.                 final UnivariateDerivative1 alphaVUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  665.                 final UnivariateDerivative1 exUD     = new UnivariateDerivative1(ex,     exDot);
  666.                 final UnivariateDerivative1 eyUD     = new UnivariateDerivative1(ey,     eyDot);
  667.                 final UnivariateDerivative1 alphaMUD = FieldCircularLatitudeArgumentUtility.trueToMean(exUD, eyUD,
  668.                         alphaVUD);
  669.                 return alphaMUD.getFirstDerivative();

  670.             case MEAN:
  671.                 return cachedAlphaDot;

  672.             case ECCENTRIC:
  673.                 final UnivariateDerivative1 alphaEUD = new UnivariateDerivative1(cachedAlpha, cachedAlphaDot);
  674.                 final UnivariateDerivative1 exUD2    = new UnivariateDerivative1(ex,     exDot);
  675.                 final UnivariateDerivative1 eyUD2    = new UnivariateDerivative1(ey,     eyDot);
  676.                 final UnivariateDerivative1 alphaMUD2 = FieldCircularLatitudeArgumentUtility.eccentricToMean(exUD2,
  677.                         eyUD2, alphaEUD);
  678.                 return alphaMUD2.getFirstDerivative();

  679.             default:
  680.                 throw new OrekitInternalError(null);
  681.         }
  682.     }

  683.     /** Get the latitude argument.
  684.      * @param type type of the angle
  685.      * @return latitude argument (rad)
  686.      */
  687.     public double getAlpha(final PositionAngleType type) {
  688.         return (type == PositionAngleType.MEAN) ? getAlphaM() :
  689.                                               ((type == PositionAngleType.ECCENTRIC) ? getAlphaE() :
  690.                                                                                    getAlphaV());
  691.     }

  692.     /** Get the latitude argument derivative.
  693.      * <p>
  694.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  695.      * </p>
  696.      * @param type type of the angle
  697.      * @return latitude argument derivative (rad/s)
  698.      * @since 9.0
  699.      */
  700.     public double getAlphaDot(final PositionAngleType type) {
  701.         return (type == PositionAngleType.MEAN) ? getAlphaMDot() :
  702.                                               ((type == PositionAngleType.ECCENTRIC) ? getAlphaEDot() :
  703.                                                                                    getAlphaVDot());
  704.     }

  705.     /** {@inheritDoc} */
  706.     @Override
  707.     public double getE() {
  708.         return FastMath.sqrt(ex * ex + ey * ey);
  709.     }

  710.     /** {@inheritDoc} */
  711.     @Override
  712.     public double getEDot() {
  713.         if (!hasNonKeplerianAcceleration()) {
  714.             return 0.;
  715.         }
  716.         return (ex * exDot + ey * eyDot) / getE();
  717.     }

  718.     /** {@inheritDoc} */
  719.     @Override
  720.     public double getI() {
  721.         return i;
  722.     }

  723.     /** {@inheritDoc} */
  724.     @Override
  725.     public double getIDot() {
  726.         return iDot;
  727.     }

  728.     /** Get the right ascension of the ascending node.
  729.      * @return right ascension of the ascending node (rad)
  730.      */
  731.     public double getRightAscensionOfAscendingNode() {
  732.         return raan;
  733.     }

  734.     /** Get the right ascension of the ascending node derivative.
  735.      * <p>
  736.      * If the orbit was created without derivatives, the value returned is {@link Double#NaN}.
  737.      * </p>
  738.      * @return right ascension of the ascending node derivative (rad/s)
  739.      * @since 9.0
  740.      */
  741.     public double getRightAscensionOfAscendingNodeDot() {
  742.         return raanDot;
  743.     }

  744.     /** {@inheritDoc} */
  745.     @Override
  746.     public double getLv() {
  747.         return getAlphaV() + raan;
  748.     }

  749.     /** {@inheritDoc} */
  750.     @Override
  751.     public double getLvDot() {
  752.         return getAlphaVDot() + raanDot;
  753.     }

  754.     /** {@inheritDoc} */
  755.     @Override
  756.     public double getLE() {
  757.         return getAlphaE() + raan;
  758.     }

  759.     /** {@inheritDoc} */
  760.     @Override
  761.     public double getLEDot() {
  762.         return getAlphaEDot() + raanDot;
  763.     }

  764.     /** {@inheritDoc} */
  765.     @Override
  766.     public double getLM() {
  767.         return getAlphaM() + raan;
  768.     }

  769.     /** {@inheritDoc} */
  770.     @Override
  771.     public double getLMDot() {
  772.         return getAlphaMDot() + raanDot;
  773.     }

  774.     /** Compute position and velocity but not acceleration.
  775.      */
  776.     private void computePVWithoutA() {

  777.         if (partialPV != null) {
  778.             // already computed
  779.             return;
  780.         }

  781.         // get equinoctial parameters
  782.         final double equEx = getEquinoctialEx();
  783.         final double equEy = getEquinoctialEy();
  784.         final double hx = getHx();
  785.         final double hy = getHy();
  786.         final double lE = getLE();

  787.         // inclination-related intermediate parameters
  788.         final double hx2   = hx * hx;
  789.         final double hy2   = hy * hy;
  790.         final double factH = 1. / (1 + hx2 + hy2);

  791.         // reference axes defining the orbital plane
  792.         final double ux = (1 + hx2 - hy2) * factH;
  793.         final double uy =  2 * hx * hy * factH;
  794.         final double uz = -2 * hy * factH;

  795.         final double vx = uy;
  796.         final double vy = (1 - hx2 + hy2) * factH;
  797.         final double vz =  2 * hx * factH;

  798.         // eccentricity-related intermediate parameters
  799.         final double exey = equEx * equEy;
  800.         final double ex2  = equEx * equEx;
  801.         final double ey2  = equEy * equEy;
  802.         final double e2   = ex2 + ey2;
  803.         final double eta  = 1 + FastMath.sqrt(1 - e2);
  804.         final double beta = 1. / eta;

  805.         // eccentric latitude argument
  806.         final SinCos scLe   = FastMath.sinCos(lE);
  807.         final double cLe    = scLe.cos();
  808.         final double sLe    = scLe.sin();
  809.         final double exCeyS = equEx * cLe + equEy * sLe;

  810.         // coordinates of position and velocity in the orbital plane
  811.         final double x      = a * ((1 - beta * ey2) * cLe + beta * exey * sLe - equEx);
  812.         final double y      = a * ((1 - beta * ex2) * sLe + beta * exey * cLe - equEy);

  813.         final double factor = FastMath.sqrt(getMu() / a) / (1 - exCeyS);
  814.         final double xdot   = factor * (-sLe + beta * equEy * exCeyS);
  815.         final double ydot   = factor * ( cLe - beta * equEx * exCeyS);

  816.         final Vector3D position =
  817.                         new Vector3D(x * ux + y * vx, x * uy + y * vy, x * uz + y * vz);
  818.         final Vector3D velocity =
  819.                         new Vector3D(xdot * ux + ydot * vx, xdot * uy + ydot * vy, xdot * uz + ydot * vz);

  820.         partialPV = new PVCoordinates(position, velocity);

  821.     }

  822.     /** Initialize cached alpha with rate.
  823.      * @param alpha input alpha
  824.      * @param alphaDot rate of input alpha
  825.      * @param inputType position angle type passed as input
  826.      * @return alpha to cache with rate
  827.      * @since 12.1
  828.      */
  829.     private UnivariateDerivative1 initializeCachedAlpha(final double alpha, final double alphaDot,
  830.                                                         final PositionAngleType inputType) {
  831.         if (cachedPositionAngleType == inputType) {
  832.             return new UnivariateDerivative1(alpha, alphaDot);

  833.         } else {
  834.             final UnivariateDerivative1 exUD = new UnivariateDerivative1(ex, exDot);
  835.             final UnivariateDerivative1 eyUD = new UnivariateDerivative1(ey, eyDot);
  836.             final UnivariateDerivative1 alphaUD = new UnivariateDerivative1(alpha, alphaDot);

  837.             switch (cachedPositionAngleType) {

  838.                 case ECCENTRIC:
  839.                     if (inputType == PositionAngleType.MEAN) {
  840.                         return FieldCircularLatitudeArgumentUtility.meanToEccentric(exUD, eyUD, alphaUD);
  841.                     } else {
  842.                         return FieldCircularLatitudeArgumentUtility.trueToEccentric(exUD, eyUD, alphaUD);
  843.                     }

  844.                 case TRUE:
  845.                     if (inputType == PositionAngleType.MEAN) {
  846.                         return FieldCircularLatitudeArgumentUtility.meanToTrue(exUD, eyUD, alphaUD);
  847.                     } else {
  848.                         return FieldCircularLatitudeArgumentUtility.eccentricToTrue(exUD, eyUD, alphaUD);
  849.                     }

  850.                 case MEAN:
  851.                     if (inputType == PositionAngleType.TRUE) {
  852.                         return FieldCircularLatitudeArgumentUtility.trueToMean(exUD, eyUD, alphaUD);
  853.                     } else {
  854.                         return FieldCircularLatitudeArgumentUtility.eccentricToMean(exUD, eyUD, alphaUD);
  855.                     }

  856.                 default:
  857.                     throw new OrekitInternalError(null);

  858.             }

  859.         }

  860.     }

  861.     /** {@inheritDoc} */
  862.     @Override
  863.     protected Vector3D initPosition() {

  864.         // get equinoctial parameters
  865.         final double equEx = getEquinoctialEx();
  866.         final double equEy = getEquinoctialEy();
  867.         final double hx = getHx();
  868.         final double hy = getHy();
  869.         final double lE = getLE();

  870.         // inclination-related intermediate parameters
  871.         final double hx2   = hx * hx;
  872.         final double hy2   = hy * hy;
  873.         final double factH = 1. / (1 + hx2 + hy2);

  874.         // reference axes defining the orbital plane
  875.         final double ux = (1 + hx2 - hy2) * factH;
  876.         final double uy =  2 * hx * hy * factH;
  877.         final double uz = -2 * hy * factH;

  878.         final double vx = uy;
  879.         final double vy = (1 - hx2 + hy2) * factH;
  880.         final double vz =  2 * hx * factH;

  881.         // eccentricity-related intermediate parameters
  882.         final double exey = equEx * equEy;
  883.         final double ex2  = equEx * equEx;
  884.         final double ey2  = equEy * equEy;
  885.         final double e2   = ex2 + ey2;
  886.         final double eta  = 1 + FastMath.sqrt(1 - e2);
  887.         final double beta = 1. / eta;

  888.         // eccentric latitude argument
  889.         final SinCos scLe   = FastMath.sinCos(lE);
  890.         final double cLe    = scLe.cos();
  891.         final double sLe    = scLe.sin();

  892.         // coordinates of position and velocity in the orbital plane
  893.         final double x      = a * ((1 - beta * ey2) * cLe + beta * exey * sLe - equEx);
  894.         final double y      = a * ((1 - beta * ex2) * sLe + beta * exey * cLe - equEy);

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

  896.     }

  897.     /** {@inheritDoc} */
  898.     @Override
  899.     protected TimeStampedPVCoordinates initPVCoordinates() {

  900.         // position and velocity
  901.         computePVWithoutA();

  902.         // acceleration
  903.         final double r2 = partialPV.getPosition().getNormSq();
  904.         final Vector3D keplerianAcceleration = new Vector3D(-getMu() / (r2 * FastMath.sqrt(r2)), partialPV.getPosition());
  905.         final Vector3D acceleration = hasNonKeplerianRates() ?
  906.                                       keplerianAcceleration.add(nonKeplerianAcceleration()) :
  907.                                       keplerianAcceleration;

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

  909.     }

  910.     /** {@inheritDoc} */
  911.     @Override
  912.     public CircularOrbit inFrame(final Frame inertialFrame) {
  913.         final PVCoordinates pvCoordinates;
  914.         if (hasNonKeplerianAcceleration()) {
  915.             pvCoordinates = getPVCoordinates(inertialFrame);
  916.         } else {
  917.             final KinematicTransform transform = getFrame().getKinematicTransformTo(inertialFrame, getDate());
  918.             pvCoordinates = transform.transformOnlyPV(getPVCoordinates());
  919.         }
  920.         final CircularOrbit circularOrbit = new CircularOrbit(pvCoordinates, inertialFrame, getDate(), getMu());
  921.         if (circularOrbit.getCachedPositionAngleType() == getCachedPositionAngleType()) {
  922.             return circularOrbit;
  923.         } else {
  924.             return circularOrbit.withCachedPositionAngleType(getCachedPositionAngleType());
  925.         }
  926.     }

  927.     /** {@inheritDoc} */
  928.     @Override
  929.     public CircularOrbit withCachedPositionAngleType(final PositionAngleType positionAngleType) {
  930.         return new CircularOrbit(a, ex, ey, i, raan, getAlpha(positionAngleType), aDot, exDot, eyDot, iDot, raanDot,
  931.                 getAlphaDot(positionAngleType), positionAngleType, getFrame(), getDate(), getMu());
  932.     }

  933.     /** {@inheritDoc} */
  934.     @Override
  935.     public CircularOrbit shiftedBy(final double dt) {
  936.         return shiftedBy(new TimeOffset(dt));
  937.     }

  938.     /** {@inheritDoc} */
  939.     @Override
  940.     public CircularOrbit shiftedBy(final TimeOffset dt) {

  941.         final double dtS = dt.toDouble();

  942.         // use Keplerian-only motion
  943.         final CircularOrbit keplerianShifted = new CircularOrbit(a, ex, ey, i, raan,
  944.                                                                  getAlphaM() + getKeplerianMeanMotion() * dtS,
  945.                                                                  PositionAngleType.MEAN, cachedPositionAngleType,
  946.                                                                  getFrame(), getDate().shiftedBy(dt), getMu());

  947.         if (dtS != 0. && hasNonKeplerianRates()) {

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

  950.             // add quadratic effect of non-Keplerian acceleration to Keplerian-only shift
  951.             keplerianShifted.computePVWithoutA();
  952.             final Vector3D fixedP   = new Vector3D(1, keplerianShifted.partialPV.getPosition(),
  953.                                                    0.5 * dtS * dtS, nonKeplerianAcceleration);
  954.             final double   fixedR2 = fixedP.getNormSq();
  955.             final double   fixedR  = FastMath.sqrt(fixedR2);
  956.             final Vector3D fixedV  = new Vector3D(1, keplerianShifted.partialPV.getVelocity(),
  957.                                                   dtS, nonKeplerianAcceleration);
  958.             final Vector3D fixedA  = new Vector3D(-getMu() / (fixedR2 * fixedR), keplerianShifted.partialPV.getPosition(),
  959.                                                   1, nonKeplerianAcceleration);

  960.             // build a new orbit, taking non-Keplerian acceleration into account
  961.             return new CircularOrbit(new TimeStampedPVCoordinates(keplerianShifted.getDate(),
  962.                                                                   fixedP, fixedV, fixedA),
  963.                                      keplerianShifted.getFrame(), keplerianShifted.getMu());

  964.         } else {
  965.             // Keplerian-only motion is all we can do
  966.             return keplerianShifted;
  967.         }

  968.     }

  969.     /** {@inheritDoc} */
  970.     @Override
  971.     protected double[][] computeJacobianMeanWrtCartesian() {


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

  973.         computePVWithoutA();
  974.         final Vector3D position = partialPV.getPosition();
  975.         final Vector3D velocity = partialPV.getVelocity();
  976.         final double x          = position.getX();
  977.         final double y          = position.getY();
  978.         final double z          = position.getZ();
  979.         final double vx         = velocity.getX();
  980.         final double vy         = velocity.getY();
  981.         final double vz         = velocity.getZ();
  982.         final double pv         = Vector3D.dotProduct(position, velocity);
  983.         final double r2         = position.getNormSq();
  984.         final double r          = FastMath.sqrt(r2);
  985.         final double v2         = velocity.getNormSq();

  986.         final double mu         = getMu();
  987.         final double oOsqrtMuA  = 1 / FastMath.sqrt(mu * a);
  988.         final double rOa        = r / a;
  989.         final double aOr        = a / r;
  990.         final double aOr2       = a / r2;
  991.         final double a2         = a * a;

  992.         final double ex2        = ex * ex;
  993.         final double ey2        = ey * ey;
  994.         final double e2         = ex2 + ey2;
  995.         final double epsilon    = FastMath.sqrt(1 - e2);
  996.         final double beta       = 1 / (1 + epsilon);

  997.         final double eCosE      = 1 - rOa;
  998.         final double eSinE      = pv * oOsqrtMuA;

  999.         final SinCos scI    = FastMath.sinCos(i);
  1000.         final SinCos scRaan = FastMath.sinCos(raan);
  1001.         final double cosI       = scI.cos();
  1002.         final double sinI       = scI.sin();
  1003.         final double cosRaan    = scRaan.cos();
  1004.         final double sinRaan    = scRaan.sin();

  1005.         // da
  1006.         fillHalfRow(2 * aOr * aOr2, position, jacobian[0], 0);
  1007.         fillHalfRow(2 * a2 / mu, velocity, jacobian[0], 3);

  1008.         // differentials of the normalized momentum
  1009.         final Vector3D danP = new Vector3D(v2, position, -pv, velocity);
  1010.         final Vector3D danV = new Vector3D(r2, velocity, -pv, position);
  1011.         final double recip  = 1 / partialPV.getMomentum().getNorm();
  1012.         final double recip2 = recip * recip;
  1013.         final Vector3D dwXP = new Vector3D(recip, new Vector3D(  0,  vz, -vy), -recip2 * sinRaan * sinI, danP);
  1014.         final Vector3D dwYP = new Vector3D(recip, new Vector3D(-vz,   0,  vx),  recip2 * cosRaan * sinI, danP);
  1015.         final Vector3D dwZP = new Vector3D(recip, new Vector3D( vy, -vx,   0), -recip2 * cosI,           danP);
  1016.         final Vector3D dwXV = new Vector3D(recip, new Vector3D(  0,  -z,   y), -recip2 * sinRaan * sinI, danV);
  1017.         final Vector3D dwYV = new Vector3D(recip, new Vector3D(  z,   0,  -x),  recip2 * cosRaan * sinI, danV);
  1018.         final Vector3D dwZV = new Vector3D(recip, new Vector3D( -y,   x,   0), -recip2 * cosI,           danV);

  1019.         // di
  1020.         fillHalfRow(sinRaan * cosI, dwXP, -cosRaan * cosI, dwYP, -sinI, dwZP, jacobian[3], 0);
  1021.         fillHalfRow(sinRaan * cosI, dwXV, -cosRaan * cosI, dwYV, -sinI, dwZV, jacobian[3], 3);

  1022.         // dRaan
  1023.         fillHalfRow(sinRaan / sinI, dwYP, cosRaan / sinI, dwXP, jacobian[4], 0);
  1024.         fillHalfRow(sinRaan / sinI, dwYV, cosRaan / sinI, dwXV, jacobian[4], 3);

  1025.         // orbital frame: (p, q, w) p along ascending node, w along momentum
  1026.         // the coordinates of the spacecraft in this frame are: (u, v, 0)
  1027.         final double u     =  x * cosRaan + y * sinRaan;
  1028.         final double cv    = -x * sinRaan + y * cosRaan;
  1029.         final double v     = cv * cosI + z * sinI;

  1030.         // du
  1031.         final Vector3D duP = new Vector3D(cv * cosRaan / sinI, dwXP,
  1032.                                           cv * sinRaan / sinI, dwYP,
  1033.                                           1, new Vector3D(cosRaan, sinRaan, 0));
  1034.         final Vector3D duV = new Vector3D(cv * cosRaan / sinI, dwXV,
  1035.                                           cv * sinRaan / sinI, dwYV);

  1036.         // dv
  1037.         final Vector3D dvP = new Vector3D(-u * cosRaan * cosI / sinI + sinRaan * z, dwXP,
  1038.                                           -u * sinRaan * cosI / sinI - cosRaan * z, dwYP,
  1039.                                           cv, dwZP,
  1040.                                           1, new Vector3D(-sinRaan * cosI, cosRaan * cosI, sinI));
  1041.         final Vector3D dvV = new Vector3D(-u * cosRaan * cosI / sinI + sinRaan * z, dwXV,
  1042.                                           -u * sinRaan * cosI / sinI - cosRaan * z, dwYV,
  1043.                                           cv, dwZV);

  1044.         final Vector3D dc1P = new Vector3D(aOr2 * (2 * eSinE * eSinE + 1 - eCosE) / r2, position,
  1045.                                             -2 * aOr2 * eSinE * oOsqrtMuA, velocity);
  1046.         final Vector3D dc1V = new Vector3D(-2 * aOr2 * eSinE * oOsqrtMuA, position,
  1047.                                             2 / mu, velocity);
  1048.         final Vector3D dc2P = new Vector3D(aOr2 * eSinE * (eSinE * eSinE - (1 - e2)) / (r2 * epsilon), position,
  1049.                                             aOr2 * (1 - e2 - eSinE * eSinE) * oOsqrtMuA / epsilon, velocity);
  1050.         final Vector3D dc2V = new Vector3D(aOr2 * (1 - e2 - eSinE * eSinE) * oOsqrtMuA / epsilon, position,
  1051.                                             eSinE / (mu * epsilon), velocity);

  1052.         final double cof1   = aOr2 * (eCosE - e2);
  1053.         final double cof2   = aOr2 * epsilon * eSinE;
  1054.         final Vector3D dexP = new Vector3D(u, dc1P,  v, dc2P, cof1, duP,  cof2, dvP);
  1055.         final Vector3D dexV = new Vector3D(u, dc1V,  v, dc2V, cof1, duV,  cof2, dvV);
  1056.         final Vector3D deyP = new Vector3D(v, dc1P, -u, dc2P, cof1, dvP, -cof2, duP);
  1057.         final Vector3D deyV = new Vector3D(v, dc1V, -u, dc2V, cof1, dvV, -cof2, duV);
  1058.         fillHalfRow(1, dexP, jacobian[1], 0);
  1059.         fillHalfRow(1, dexV, jacobian[1], 3);
  1060.         fillHalfRow(1, deyP, jacobian[2], 0);
  1061.         fillHalfRow(1, deyV, jacobian[2], 3);

  1062.         final double cle = u / a + ex - eSinE * beta * ey;
  1063.         final double sle = v / a + ey + eSinE * beta * ex;
  1064.         final double m1  = beta * eCosE;
  1065.         final double m2  = 1 - m1 * eCosE;
  1066.         final double m3  = (u * ey - v * ex) + eSinE * beta * (u * ex + v * ey);
  1067.         final double m4  = -sle + cle * eSinE * beta;
  1068.         final double m5  = cle + sle * eSinE * beta;
  1069.         fillHalfRow((2 * m3 / r + aOr * eSinE + m1 * eSinE * (1 + m1 - (1 + aOr) * m2) / epsilon) / r2, position,
  1070.                     (m1 * m2 / epsilon - 1) * oOsqrtMuA, velocity,
  1071.                     m4, dexP, m5, deyP, -sle / a, duP, cle / a, dvP,
  1072.                     jacobian[5], 0);
  1073.         fillHalfRow((m1 * m2 / epsilon - 1) * oOsqrtMuA, position,
  1074.                     (2 * m3 + eSinE * a + m1 * eSinE * r * (eCosE * beta * 2 - aOr * m2) / epsilon) / mu, velocity,
  1075.                     m4, dexV, m5, deyV, -sle / a, duV, cle / a, dvV,
  1076.                     jacobian[5], 3);

  1077.         return jacobian;

  1078.     }

  1079.     /** {@inheritDoc} */
  1080.     @Override
  1081.     protected double[][] computeJacobianEccentricWrtCartesian() {

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

  1084.         // Differentiating the Kepler equation aM = aE - ex sin aE + ey cos aE leads to:
  1085.         // daM = (1 - ex cos aE - ey sin aE) daE - sin aE dex + cos aE dey
  1086.         // which is inverted and rewritten as:
  1087.         // daE = a/r daM + sin aE a/r dex - cos aE a/r dey
  1088.         final double alphaE = getAlphaE();
  1089.         final SinCos scAe   = FastMath.sinCos(alphaE);
  1090.         final double cosAe  = scAe.cos();
  1091.         final double sinAe  = scAe.sin();
  1092.         final double aOr    = 1 / (1 - ex * cosAe - ey * sinAe);

  1093.         // update longitude row
  1094.         final double[] rowEx = jacobian[1];
  1095.         final double[] rowEy = jacobian[2];
  1096.         final double[] rowL  = jacobian[5];
  1097.         for (int j = 0; j < 6; ++j) {
  1098.             rowL[j] = aOr * (rowL[j] + sinAe * rowEx[j] - cosAe * rowEy[j]);
  1099.         }

  1100.         return jacobian;

  1101.     }

  1102.     /** {@inheritDoc} */
  1103.     @Override
  1104.     protected double[][] computeJacobianTrueWrtCartesian() {

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

  1107.         // Differentiating the eccentric latitude equation
  1108.         // tan((aV - aE)/2) = [ex sin aE - ey cos aE] / [sqrt(1-ex^2-ey^2) + 1 - ex cos aE - ey sin aE]
  1109.         // leads to
  1110.         // cT (daV - daE) = cE daE + cX dex + cY dey
  1111.         // with
  1112.         // cT = [d^2 + (ex sin aE - ey cos aE)^2] / 2
  1113.         // d  = 1 + sqrt(1-ex^2-ey^2) - ex cos aE - ey sin aE
  1114.         // cE = (ex cos aE + ey sin aE) (sqrt(1-ex^2-ey^2) + 1) - ex^2 - ey^2
  1115.         // cX =  sin aE (sqrt(1-ex^2-ey^2) + 1) - ey + ex (ex sin aE - ey cos aE) / sqrt(1-ex^2-ey^2)
  1116.         // cY = -cos aE (sqrt(1-ex^2-ey^2) + 1) + ex + ey (ex sin aE - ey cos aE) / sqrt(1-ex^2-ey^2)
  1117.         // which can be solved to find the differential of the true latitude
  1118.         // daV = (cT + cE) / cT daE + cX / cT deX + cY / cT deX
  1119.         final double alphaE    = getAlphaE();
  1120.         final SinCos scAe      = FastMath.sinCos(alphaE);
  1121.         final double cosAe     = scAe.cos();
  1122.         final double sinAe     = scAe.sin();
  1123.         final double eSinE     = ex * sinAe - ey * cosAe;
  1124.         final double ecosE     = ex * cosAe + ey * sinAe;
  1125.         final double e2        = ex * ex + ey * ey;
  1126.         final double epsilon   = FastMath.sqrt(1 - e2);
  1127.         final double onePeps   = 1 + epsilon;
  1128.         final double d         = onePeps - ecosE;
  1129.         final double cT        = (d * d + eSinE * eSinE) / 2;
  1130.         final double cE        = ecosE * onePeps - e2;
  1131.         final double cX        = ex * eSinE / epsilon - ey + sinAe * onePeps;
  1132.         final double cY        = ey * eSinE / epsilon + ex - cosAe * onePeps;
  1133.         final double factorLe  = (cT + cE) / cT;
  1134.         final double factorEx  = cX / cT;
  1135.         final double factorEy  = cY / cT;

  1136.         // update latitude row
  1137.         final double[] rowEx = jacobian[1];
  1138.         final double[] rowEy = jacobian[2];
  1139.         final double[] rowA = jacobian[5];
  1140.         for (int j = 0; j < 6; ++j) {
  1141.             rowA[j] = factorLe * rowA[j] + factorEx * rowEx[j] + factorEy * rowEy[j];
  1142.         }

  1143.         return jacobian;

  1144.     }

  1145.     /** {@inheritDoc} */
  1146.     @Override
  1147.     public void addKeplerContribution(final PositionAngleType type, final double gm,
  1148.                                       final double[] pDot) {
  1149.         pDot[5] += computeKeplerianAlphaDot(type, a, ex, ey, gm, cachedAlpha, cachedPositionAngleType);
  1150.     }

  1151.     /**
  1152.      * Compute rate of argument of latitude.
  1153.      * @param type position angle type of rate
  1154.      * @param a semi major axis
  1155.      * @param ex ex
  1156.      * @param ey ey
  1157.      * @param mu mu
  1158.      * @param alpha argument of latitude
  1159.      * @param cachedType position angle type of passed alpha
  1160.      * @return first-order time derivative for alpha
  1161.      * @since 12.2
  1162.      */
  1163.     private static double computeKeplerianAlphaDot(final PositionAngleType type, final double a, final double ex,
  1164.                                                    final double ey, final double mu,
  1165.                                                    final double alpha, final PositionAngleType cachedType) {
  1166.         final double n  = FastMath.sqrt(mu / a) / a;
  1167.         if (type == PositionAngleType.MEAN) {
  1168.             return n;
  1169.         }
  1170.         final double ksi;
  1171.         final SinCos sc;
  1172.         if (type == PositionAngleType.ECCENTRIC) {
  1173.             sc = FastMath.sinCos(CircularLatitudeArgumentUtility.convertAlpha(cachedType, alpha, ex, ey, type));
  1174.             ksi   = 1. / (1 - ex * sc.cos() - ey * sc.sin());
  1175.             return n * ksi;
  1176.         } else { // TRUE
  1177.             sc = FastMath.sinCos(CircularLatitudeArgumentUtility.convertAlpha(cachedType, alpha, ex, ey, type));
  1178.             final double oMe2  = 1 - ex * ex - ey * ey;
  1179.             ksi   = 1 + ex * sc.cos() + ey * sc.sin();
  1180.             return n * ksi * ksi / (oMe2 * FastMath.sqrt(oMe2));
  1181.         }
  1182.     }

  1183.     /**  Returns a string representation of this Orbit object.
  1184.      * @return a string representation of this object
  1185.      */
  1186.     public String toString() {
  1187.         return new StringBuilder().append("circular parameters: ").append('{').
  1188.                                   append("a: ").append(a).
  1189.                                   append(", ex: ").append(ex).append(", ey: ").append(ey).
  1190.                                   append(", i: ").append(FastMath.toDegrees(i)).
  1191.                                   append(", raan: ").append(FastMath.toDegrees(raan)).
  1192.                                   append(", alphaV: ").append(FastMath.toDegrees(getAlphaV())).
  1193.                                   append(";}").toString();
  1194.     }

  1195.     /** {@inheritDoc} */
  1196.     @Override
  1197.     public PositionAngleType getCachedPositionAngleType() {
  1198.         return cachedPositionAngleType;
  1199.     }

  1200.     /** {@inheritDoc} */
  1201.     @Override
  1202.     public boolean hasNonKeplerianRates() {
  1203.         return hasNonKeplerianAcceleration();
  1204.     }

  1205.     /** {@inheritDoc} */
  1206.     @Override
  1207.     public CircularOrbit withKeplerianRates() {
  1208.         final PositionAngleType positionAngleType = getCachedPositionAngleType();
  1209.         return new CircularOrbit(a, ex, ey, i, raan, cachedAlpha, positionAngleType, positionAngleType,
  1210.                 getFrame(), getDate(), getMu());
  1211.     }

  1212. }