FixedZHomothety.java

  1. /* Copyright 2013-2022 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.rugged.los;

  18. import java.util.stream.Stream;

  19. import org.hipparchus.analysis.differentiation.Derivative;
  20. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.util.FastMath;
  23. import org.orekit.rugged.utils.DerivativeGenerator;
  24. import org.orekit.utils.ParameterDriver;
  25. import org.orekit.utils.ParameterObserver;

  26. /** {@link TimeIndependentLOSTransform LOS transform} based on a homothety along the Z axis.
  27.  * @author Lucie Labatallee
  28.  * @author Guylaine Prat
  29.  * @see LOSBuilder
  30.  * @since 2.0
  31.  */
  32. public class FixedZHomothety implements TimeIndependentLOSTransform {

  33.     /** Parameters scaling factor.
  34.      * <p>
  35.      * We use a power of 2 to avoid numeric noise introduction
  36.      * in the multiplications/divisions sequences.
  37.      * </p>
  38.      */
  39.     private final double SCALE = FastMath.scalb(1.0, 0);

  40.     /** Homothety factor. */
  41.     private double factor;

  42.     /** Underlying homothety with derivatives. */
  43.     private Derivative<?> factorDS;

  44.     /** Driver for homothety factor. */
  45.     private final ParameterDriver factorDriver;

  46.     /** Simple constructor.
  47.      * <p>
  48.      * The single parameter is the homothety factor.
  49.      * </p>
  50.      * @param name name of the homothety (used for estimated parameters identification)
  51.      * @param factorvalue homothety factor
  52.      */
  53.     public FixedZHomothety(final String name, final double factorvalue) {

  54.         this.factor   = factorvalue;
  55.         this.factorDS = null;
  56.         this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, 0, Double.POSITIVE_INFINITY);
  57.         factorDriver.addObserver(new ParameterObserver() {
  58.             @Override
  59.             public void valueChanged(final double previousValue, final ParameterDriver driver) {
  60.                 // reset factor to zero, they will be evaluated lazily if needed
  61.                 factor = 0.0;
  62.                 factorDS = null;
  63.             }
  64.         });
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public Stream<ParameterDriver> getParametersDrivers() {
  69.         return Stream.of(factorDriver);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public Vector3D transformLOS(final int i, final Vector3D los) {

  74.         if (factor == 0.0) {
  75.             // lazy evaluation of the homothety
  76.             factor = factorDriver.getValue();
  77.         }
  78.         return new Vector3D(los.getX(), los.getY(), factor * los.getZ());
  79.     }

  80.     /** {@inheritDoc} */
  81.     @SuppressWarnings("unchecked")
  82.     @Override
  83.     public <T extends Derivative<T>> FieldVector3D<T> transformLOS(final int i, final FieldVector3D<T> los,
  84.                                                                    final DerivativeGenerator<T> generator) {
  85.         final T factorD;
  86.         if (factorDS == null || !factorDS.getField().equals(generator.getField())) {

  87.             // lazy evaluation of the homothety
  88.             factorD = generator.variable(factorDriver);

  89.             // cache evaluated homothety
  90.             factorDS = factorD;

  91.         } else {
  92.             // reuse cached value
  93.             factorD  = (T) factorDS;
  94.         }

  95.         return new FieldVector3D<>(los.getX(), los.getY(), factorD.multiply(los.getZ()));

  96.     }

  97. }