TwoDVariation.java

  1. /* Copyright 2002-2024 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. import org.hipparchus.util.FastMath;
  19. import org.hipparchus.util.MathUtils;

  20. /**
  21.  * Interpolator for 2D phase center variation data.
  22.  *
  23.  * @author Luc Maisonobe
  24.  * @since 9.2
  25.  */
  26. public class TwoDVariation implements PhaseCenterVariationFunction {

  27.     /** Start polar angle. */
  28.     private final double polarStart;

  29.     /** Step between grid points. */
  30.     private final double polarStep;

  31.     /** Step between grid points. */
  32.     private final double azimuthStep;

  33.     /** Sampled phase center variations. */
  34.     private final double[][] variations;

  35.     /** Simple constructor.
  36.      * @param polarStart start polar angle
  37.      * @param polarStep between grid points
  38.      * @param azimuthStep step between grid points
  39.      * @param variations sampled phase center variations
  40.      */
  41.     public TwoDVariation(final double polarStart, final double polarStep,
  42.                          final double azimuthStep, final double[][] variations) {
  43.         this.polarStart  = polarStart;
  44.         this.polarStep   = polarStep;
  45.         this.azimuthStep = azimuthStep;
  46.         this.variations  = new double[variations.length][];
  47.         for (int i = 0; i < variations.length; ++i) {
  48.             this.variations[i] = variations[i].clone();
  49.         }
  50.     }

  51.     /** {@inheritDoc} */
  52.     @Override
  53.     public double value(final double polarAngle, final double azimuthAngle) {

  54.         // find surrounding points
  55.         final double az      = MathUtils.normalizeAngle(azimuthAngle, FastMath.PI);
  56.         final int    iBase   = (int) FastMath.floor(az / azimuthStep);
  57.         final int    i       = FastMath.max(0, FastMath.min(variations.length - 2, iBase));
  58.         final int    jBase   = (int) FastMath.floor((polarAngle - polarStart) / polarStep);
  59.         final int    j       = FastMath.max(0, FastMath.min(variations[i].length - 2, jBase));

  60.         final double aInf    = i * azimuthStep;
  61.         final double aSup    = aInf + azimuthStep;
  62.         final double pInf    = polarStart + j * polarStep;
  63.         final double pSup    = pInf + polarStep;

  64.         final double vInfInf = variations[i][j];
  65.         final double vInfSup = variations[i][j + 1];
  66.         final double vSupInf = variations[i + 1][j];
  67.         final double vSupSup = variations[i + 1][j + 1];

  68.         // bilinear interpolation
  69.         final double vInf = ((polarAngle - pInf) * vInfSup + (pSup - polarAngle) * vInfInf) / polarStep;
  70.         final double vSup = ((polarAngle - pInf) * vSupSup + (pSup - polarAngle) * vSupInf) / polarStep;
  71.         return ((az - aInf) * vSup + (aSup - az) * vInf) / azimuthStep;

  72.     }

  73. }