1 /* Copyright 2002-2026 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.Serial;
20 import java.io.Serializable;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.orekit.utils.Constants;
24
25 /**
26 * Polynomial nutation function.
27 *
28 * @author Luc Maisonobe
29 * @see PoissonSeries
30 */
31 public class PolynomialNutation implements Serializable {
32
33 /** Serializable UID. */
34 @Serial
35 private static final long serialVersionUID = 20131007L;
36
37 /** Coefficients of the polynomial part. */
38 private final double[] coefficients;
39
40 /** Build a polynomial from its coefficients.
41 * @param coefficients polynomial coefficients in increasing degree
42 */
43 public PolynomialNutation(final double... coefficients) {
44 this.coefficients = coefficients.clone();
45 }
46
47 /** Evaluate the value of the polynomial.
48 * @param tc date offset in Julian centuries
49 * @return value of the polynomial
50 */
51 public double value(final double tc) {
52
53 double p = 0;
54 for (int i = coefficients.length - 1; i >= 0; --i) {
55 p = p * tc + coefficients[i];
56 }
57
58 return p;
59
60 }
61
62 /** Evaluate the time derivative of the polynomial.
63 * @param tc date offset in Julian centuries
64 * @return time derivative of the polynomial
65 */
66 public double derivative(final double tc) {
67
68 double p = 0;
69 for (int i = coefficients.length - 1; i > 0; --i) {
70 p = p * tc + i * coefficients[i];
71 }
72
73 return p / Constants.JULIAN_CENTURY;
74
75 }
76
77 /** Evaluate the value of the polynomial.
78 * @param tc date offset in Julian centuries
79 * @param <T> type of the filed elements
80 * @return value of the polynomial
81 */
82 public <T extends CalculusFieldElement<T>> T value(final T tc) {
83
84 T p = tc.getField().getZero();
85 for (int i = coefficients.length - 1; i >= 0; --i) {
86 p = p.multiply(tc).add(coefficients[i]);
87 }
88
89 return p;
90
91 }
92
93 /** Evaluate the time derivative of the polynomial.
94 * @param tc date offset in Julian centuries
95 * @param <T> type of the filed elements
96 * @return time derivative of the polynomial
97 */
98 public <T extends CalculusFieldElement<T>> T derivative(final T tc) {
99
100 T p = tc.getField().getZero();
101 for (int i = coefficients.length - 1; i > 0; --i) {
102 p = p.multiply(tc).add( i * coefficients[i]);
103 }
104
105 return p.divide(Constants.JULIAN_CENTURY);
106
107 }
108
109 }