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.gnss.antenna;
18  
19  import org.hipparchus.util.FastMath;
20  
21  /**
22   * Interpolator for 1D phase center variation data.
23   *
24   * @author Luc Maisonobe
25   * @since 9.2
26   */
27  public class OneDVariation implements PhaseCenterVariationFunction {
28  
29      /** Start polar angle. */
30      private final double polarStart;
31  
32      /** Step between grid points. */
33      private final double polarStep;
34  
35      /** Sampled phase center variations. */
36      private final double[] variations;
37  
38      /** Simple constructor.
39       * @param polarStart start polar angle
40       * @param polarStep between grid points
41       * @param variations sampled phase center variations
42       */
43      public OneDVariation(final double polarStart, final double polarStep, final double[] variations) {
44          this.polarStart = polarStart;
45          this.polarStep  = polarStep;
46          this.variations = variations.clone();
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public double value(final double polarAngle, final double azimuthAngle) {
52  
53          // find surrounding points
54          final int    jBase = (int) FastMath.floor((polarAngle - polarStart) / polarStep);
55          final int    j     = FastMath.max(0, FastMath.min(variations.length - 2, jBase));
56  
57          final double pInf  = polarStart + j * polarStep;
58          final double pSup  = pInf + polarStep;
59  
60          final double vInf  = variations[j];
61          final double vSup  = variations[j + 1];
62  
63          // linear interpolation
64          return ((polarAngle - pInf) * vSup + (pSup - polarAngle) * vInf) / polarStep;
65  
66      }
67  
68  }