1   /* Copyright 2002-2023 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.data;
18  
19  import java.io.Serializable;
20  
21  import org.hipparchus.CalculusFieldElement;
22  import org.orekit.utils.Constants;
23  
24  /**
25   * Polynomial nutation function.
26   *
27   * @author Luc Maisonobe
28   * @see PoissonSeries
29   */
30  public class PolynomialNutation implements Serializable {
31  
32      /** Serializable UID. */
33      private static final long serialVersionUID = 20131007L;
34  
35      /** Coefficients of the polynomial part. */
36      private double[] coefficients;
37  
38      /** Build a polynomial from its coefficients.
39       * @param coefficients polynomial coefficients in increasing degree
40       */
41      public PolynomialNutation(final double... coefficients) {
42          this.coefficients = coefficients.clone();
43      }
44  
45      /** Evaluate the value of the polynomial.
46       * @param tc date offset in Julian centuries
47       * @return value of the polynomial
48       */
49      public double value(final double tc) {
50  
51          double p = 0;
52          for (int i = coefficients.length - 1; i >= 0; --i) {
53              p = p * tc + coefficients[i];
54          }
55  
56          return p;
57  
58      }
59  
60      /** Evaluate the time derivative of the polynomial.
61       * @param tc date offset in Julian centuries
62       * @return time derivative of the polynomial
63       */
64      public double derivative(final double tc) {
65  
66          double p = 0;
67          for (int i = coefficients.length - 1; i > 0; --i) {
68              p = p * tc + i * coefficients[i];
69          }
70  
71          return p / Constants.JULIAN_CENTURY;
72  
73      }
74  
75      /** Evaluate the value of the polynomial.
76       * @param tc date offset in Julian centuries
77       * @param <T> type of the filed elements
78       * @return value of the polynomial
79       */
80      public <T extends CalculusFieldElement<T>> T value(final T tc) {
81  
82          T p = tc.getField().getZero();
83          for (int i = coefficients.length - 1; i >= 0; --i) {
84              p = p.multiply(tc).add(coefficients[i]);
85          }
86  
87          return p;
88  
89      }
90  
91      /** Evaluate the time derivative of the polynomial.
92       * @param tc date offset in Julian centuries
93       * @param <T> type of the filed elements
94       * @return time derivative of the polynomial
95       */
96      public <T extends CalculusFieldElement<T>> T derivative(final T tc) {
97  
98          T p = tc.getField().getZero();
99          for (int i = coefficients.length - 1; i > 0; --i) {
100             p = p.multiply(tc).add( i * coefficients[i]);
101         }
102 
103         return p.divide(Constants.JULIAN_CENTURY);
104 
105     }
106 
107 }