GHmsjPolynomials.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.propagation.semianalytical.dsst.utilities;

  18. import org.hipparchus.util.FastMath;

  19. /** Compute the G<sub>ms</sub><sup>j</sup> and the H<sub>ms</sub><sup>j</sup>
  20.  *  polynomials in the equinoctial elements h, k and the direction cosines α and β
  21.  *  and their partial derivatives with respect to k, h, α and β.
  22.  *  <p>
  23.  *  The expressions used are equations 2.7.5-(1)(2) from the Danielson paper.
  24.  *  </p>
  25.  *  @author Romain Di Costanzo
  26.  */
  27. public class GHmsjPolynomials {

  28.     /** C<sub>j</sub>(k, h), S<sub>j</sub>(k, h) coefficient.
  29.      * (k, h) are the (x, y) component of the eccentricity vector in equinoctial elements
  30.      */
  31.     private final CjSjCoefficient cjsjKH;

  32.     /** C<sub>j</sub>(α, β), S<sub>j</sub>(α, β) coefficient.
  33.      * (α, β) are the direction cosines
  34.      */
  35.     private final CjSjCoefficient cjsjAB;

  36.     /** Is the orbit represented as a retrograde orbit.
  37.      *  I = -1 if yes, +1 otherwise.
  38.      */
  39.     private int                   I;

  40.     /** Create a set of G<sub>ms</sub><sup>j</sup> and H<sub>ms</sub><sup>j</sup> polynomials.
  41.      *  @param k X component of the eccentricity vector
  42.      *  @param h Y component of the eccentricity vector
  43.      *  @param alpha direction cosine α
  44.      *  @param beta direction cosine β
  45.      *  @param retroFactor -1 if the orbit is represented as retrograde, +1 otherwise
  46.      **/
  47.     public GHmsjPolynomials(final double k, final double h,
  48.                             final double alpha, final double beta,
  49.                             final int retroFactor) {
  50.         this.cjsjKH = new CjSjCoefficient(k, h);
  51.         this.cjsjAB = new CjSjCoefficient(alpha, beta);
  52.         this.I = retroFactor;
  53.     }

  54.     /** Get the G<sub>ms</sub><sup>j</sup> coefficient.
  55.      * @param m m subscript
  56.      * @param s s subscript
  57.      * @param j order
  58.      * @return the G<sub>ms</sub><sup>j</sup>
  59.      */
  60.     public double getGmsj(final int m, final int s, final int j) {
  61.         final int sMj = FastMath.abs(s - j);
  62.         double gms = 0d;
  63.         if (FastMath.abs(s) <= m) {
  64.             final int mMis = m - I * s;
  65.             gms = cjsjKH.getCj(sMj) * cjsjAB.getCj(mMis) -
  66.                   I * sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getSj(mMis);
  67.         } else {
  68.             final int sMim = FastMath.abs(s - I * m);
  69.             gms = cjsjKH.getCj(sMj) * cjsjAB.getCj(sMim) +
  70.                   sgn(s - j) * sgn(s - m) * cjsjKH.getSj(sMj) * cjsjAB.getSj(sMim);
  71.         }
  72.         return gms;
  73.     }

  74.     /** Get the H<sub>ms</sub><sup>j</sup> coefficient.
  75.      * @param m m subscript
  76.      * @param s s subscript
  77.      * @param j order
  78.      * @return the H<sub>ms</sub><sup>j</sup>
  79.      */
  80.     public double getHmsj(final int m, final int s, final int j) {
  81.         final int sMj = FastMath.abs(s - j);
  82.         double hms = 0d;
  83.         if (FastMath.abs(s) <= m) {
  84.             final int mMis = m - I * s;
  85.             hms = I * cjsjKH.getCj(sMj) * cjsjAB.getSj(mMis) + sgn(s - j) *
  86.                   cjsjKH.getSj(sMj) * cjsjAB.getCj(mMis);
  87.         } else {
  88.             final int sMim = FastMath.abs(s - I * m);
  89.             hms = -sgn(s - m) * cjsjKH.getCj(sMj) * cjsjAB.getSj(sMim) +
  90.                    sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getCj(sMim);
  91.         }
  92.         return hms;
  93.     }

  94.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>k</sub> coefficient.
  95.      * @param m m subscript
  96.      * @param s s subscript
  97.      * @param j order
  98.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>k</sub>
  99.      */
  100.     public double getdGmsdk(final int m, final int s, final int j) {
  101.         final int sMj = FastMath.abs(s - j);
  102.         double dGmsdk = 0d;
  103.         if (FastMath.abs(s) <= m) {
  104.             final int mMis = m - I * s;
  105.             dGmsdk = cjsjKH.getDcjDk(sMj) * cjsjAB.getCj(mMis) -
  106.                    I * sgn(s - j) * cjsjKH.getDsjDk(sMj) * cjsjAB.getSj(mMis);
  107.         } else {
  108.             final int sMim = FastMath.abs(s - I * m);
  109.             dGmsdk = cjsjKH.getDcjDk(sMj) * cjsjAB.getCj(sMim) +
  110.                     sgn(s - j) * sgn(s - m) * cjsjKH.getDsjDk(sMj) * cjsjAB.getSj(sMim);
  111.         }
  112.         return dGmsdk;
  113.     }

  114.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>h</sub> coefficient.
  115.      * @param m m subscript
  116.      * @param s s subscript
  117.      * @param j order
  118.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>h</sub>
  119.      */
  120.     public double getdGmsdh(final int m, final int s, final int j) {
  121.         final int sMj = FastMath.abs(s - j);
  122.         double dGmsdh = 0d;
  123.         if (FastMath.abs(s) <= m) {
  124.             final int mMis = m - I * s;
  125.             dGmsdh = cjsjKH.getDcjDh(sMj) * cjsjAB.getCj(mMis) -
  126.                     I * sgn(s - j) * cjsjKH.getDsjDh(sMj) * cjsjAB.getSj(mMis);
  127.         } else {
  128.             final int sMim = FastMath.abs(s - I * m);
  129.             dGmsdh = cjsjKH.getDcjDh(sMj) * cjsjAB.getCj(sMim) +
  130.                     sgn(s - j) * sgn(s - m) * cjsjKH.getDsjDh(sMj) * cjsjAB.getSj(sMim);
  131.         }
  132.         return dGmsdh;
  133.     }

  134.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>α</sub> coefficient.
  135.      * @param m m subscript
  136.      * @param s s subscript
  137.      * @param j order
  138.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>α</sub>
  139.      */
  140.     public double getdGmsdAlpha(final int m, final int s, final int j) {
  141.         final int sMj  = FastMath.abs(s - j);
  142.         double dGmsdAl = 0d;
  143.         if (FastMath.abs(s) <= m) {
  144.             final int mMis = m - I * s;
  145.             dGmsdAl = cjsjKH.getCj(sMj) * cjsjAB.getDcjDk(mMis) -
  146.                    I * sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDsjDk(mMis);
  147.         } else {
  148.             final int sMim = FastMath.abs(s - I * m);
  149.             dGmsdAl = cjsjKH.getCj(sMj) * cjsjAB.getDcjDk(sMim) +
  150.                     sgn(s - j) * sgn(s - m) * cjsjKH.getSj(sMj) * cjsjAB.getDsjDk(sMim);
  151.         }
  152.         return dGmsdAl;
  153.     }

  154.     /** Get the dG<sub>ms</sub><sup>j</sup> / d<sub>β</sub> coefficient.
  155.      * @param m m subscript
  156.      * @param s s subscript
  157.      * @param j order
  158.      * @return dG<sub>ms</sub><sup>j</sup> / d<sub>β</sub>
  159.      */
  160.     public double getdGmsdBeta(final int m, final int s, final int j) {
  161.         final int sMj = FastMath.abs(s - j);
  162.         double dGmsdBe = 0d;
  163.         if (FastMath.abs(s) <= m) {
  164.             final int mMis = m - I * s;
  165.             dGmsdBe = cjsjKH.getCj(sMj) * cjsjAB.getDcjDh(mMis) -
  166.                     I * sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDsjDh(mMis);
  167.         } else {
  168.             final int sMim = FastMath.abs(s - I * m);
  169.             dGmsdBe = cjsjKH.getCj(sMj) * cjsjAB.getDcjDh(sMim) +
  170.                     sgn(s - j) * sgn(s - m) * cjsjKH.getSj(sMj) * cjsjAB.getDsjDh(sMim);
  171.         }
  172.         return dGmsdBe;
  173.     }

  174.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>k</sub> coefficient.
  175.      * @param m m subscript
  176.      * @param s s subscript
  177.      * @param j order
  178.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>k</sub>
  179.      */
  180.     public double getdHmsdk(final int m, final int s, final int j) {
  181.         final int sMj = FastMath.abs(s - j);
  182.         double dHmsdk = 0d;
  183.         if (FastMath.abs(s) <= m) {
  184.             final int mMis = m - I * s;
  185.             dHmsdk = I * cjsjKH.getDcjDk(sMj) * cjsjAB.getSj(mMis) +
  186.                     sgn(s - j) * cjsjKH.getDsjDk(sMj) * cjsjAB.getCj(mMis);
  187.         } else {
  188.             final int sMim = FastMath.abs(s - I * m);
  189.             dHmsdk = -sgn(s - m) * cjsjKH.getDcjDk(sMj) * cjsjAB.getSj(sMim) +
  190.                     sgn(s - j) * cjsjKH.getDsjDk(sMj) * cjsjAB.getCj(sMim);
  191.         }
  192.         return dHmsdk;
  193.     }

  194.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>h</sub> coefficient.
  195.      * @param m m subscript
  196.      * @param s s subscript
  197.      * @param j order
  198.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>h</sub>
  199.      */
  200.     public double getdHmsdh(final int m,  final int s, final int j) {
  201.         final int sMj = FastMath.abs(s - j);
  202.         double dHmsdh = 0d;
  203.         if (FastMath.abs(s) <= m) {
  204.             final int mMis = m - I * s;
  205.             dHmsdh = I * cjsjKH.getDcjDh(sMj) * cjsjAB.getSj(mMis) +
  206.                     sgn(s - j) * cjsjKH.getDsjDh(sMj) * cjsjAB.getCj(mMis);
  207.         } else {
  208.             final int sMim = FastMath.abs(s - I * m);
  209.             dHmsdh = -sgn(s - m) * cjsjKH.getDcjDh(sMj) * cjsjAB.getSj(sMim) +
  210.                     sgn(s - j) * cjsjKH.getDsjDh(sMj) * cjsjAB.getCj(sMim);
  211.         }
  212.         return dHmsdh;
  213.     }

  214.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>α</sub> coefficient.
  215.      * @param m m subscript
  216.      * @param s s subscript
  217.      * @param j order
  218.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>α</sub>
  219.      */
  220.     public double getdHmsdAlpha(final int m, final int s, final int j) {
  221.         final int sMj  = FastMath.abs(s - j);
  222.         double dHmsdAl = 0d;
  223.         if (FastMath.abs(s) <= m) {
  224.             final int mMis = m - I * s;
  225.             dHmsdAl = I * cjsjKH.getCj(sMj) * cjsjAB.getDsjDk(mMis) +
  226.                     sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDcjDk(mMis);
  227.         } else {
  228.             final int sMim = FastMath.abs(s - I * m);
  229.             dHmsdAl = -sgn(s - m) * cjsjKH.getCj(sMj) * cjsjAB.getDsjDk(sMim) +
  230.                     sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDcjDk(sMim);
  231.         }
  232.         return dHmsdAl;
  233.     }

  234.     /** Get the dH<sub>ms</sub><sup>j</sup> / d<sub>β</sub> coefficient.
  235.      * @param m m subscript
  236.      * @param s s subscript
  237.      * @param j order
  238.      * @return dH<sub>ms</sub><sup>j</sup> / d<sub>β</sub>
  239.      */
  240.     public double getdHmsdBeta(final int m, final int s, final int j) {
  241.         final int sMj = FastMath.abs(s - j);
  242.         double dHmsdBe = 0d;
  243.         if (FastMath.abs(s) <= m) {
  244.             final int mMis = m - I * s;
  245.             dHmsdBe = I * cjsjKH.getCj(sMj) * cjsjAB.getDsjDh(mMis) +
  246.                    sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDcjDh(mMis);
  247.         } else {
  248.             final int sMim = FastMath.abs(s - I * m);
  249.             dHmsdBe = -sgn(s - m) * cjsjKH.getCj(sMj) * cjsjAB.getDsjDh(sMim) +
  250.                     sgn(s - j) * cjsjKH.getSj(sMj) * cjsjAB.getDcjDh(sMim);
  251.         }
  252.         return dHmsdBe;
  253.     }

  254.     /** Get the sign of an integer.
  255.      *  @param i number on which evaluation is done
  256.      *  @return -1 or +1 depending on sign of i
  257.      */
  258.     private int sgn(final int i) {
  259.         return (i < 0) ? -1 : 1;
  260.     }
  261. }