FixedZHomothety.java

  1. /* Copyright 2013-2017 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.DerivativeStructure;
  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.errors.OrekitException;
  24. import org.orekit.rugged.errors.RuggedException;
  25. import org.orekit.rugged.utils.DSGenerator;
  26. import org.orekit.utils.ParameterDriver;
  27. import org.orekit.utils.ParameterObserver;

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

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

  43.     /** Homothety factor. */
  44.     private double factor;

  45.     /** Underlying homothety with derivatives. */
  46.     private DerivativeStructure factorDS;

  47.     /** Driver for homothety factor. */
  48.     private final ParameterDriver factorDriver;

  49.     /** Simple constructor.
  50.      * <p>
  51.      * The single parameter is the homothety factor.
  52.      * </p>
  53.      * @param name name of the homothety (used for estimated parameters identification)
  54.      * @param factorvalue homothety factor
  55.      */
  56.     public FixedZHomothety(final String name, final double factorvalue) {
  57.         this.factor   = factorvalue;
  58.         this.factorDS = null;
  59.         try {
  60.             this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, 0, Double.POSITIVE_INFINITY);
  61.             factorDriver.addObserver(new ParameterObserver() {
  62.                 @Override
  63.                 public void valueChanged(final double previousValue, final ParameterDriver driver) {
  64.                     // reset factor to zero, they will be evaluated lazily if needed
  65.                     factor = 0.0;
  66.                     factorDS = null;
  67.                 }
  68.             });
  69.         } catch (OrekitException oe) {
  70.             // this should never happen
  71.             throw RuggedException.createInternalError(oe);
  72.         }
  73.     }

  74.     /** {@inheritDoc} */
  75.     @Override
  76.     public Stream<ParameterDriver> getParametersDrivers() {
  77.         return Stream.of(factorDriver);
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public Vector3D transformLOS(final int i, final Vector3D los) {

  82.         if (factor == 0.0) {
  83.             // lazy evaluation of the homothety
  84.             factor = factorDriver.getValue();
  85.         }
  86.         return new Vector3D(los.getX(), los.getY(), factor * los.getZ());
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public FieldVector3D<DerivativeStructure> transformLOS(final int i, final FieldVector3D<DerivativeStructure> los,
  91.                                                            final DSGenerator generator) {
  92.         if (factorDS == null) {
  93.             // lazy evaluation of the homothety
  94.             factorDS = generator.variable(factorDriver);
  95.         }
  96.         return new FieldVector3D<DerivativeStructure>(los.getX(), los.getY(), factorDS.multiply(los.getZ()));
  97.     }

  98. }