1   /* Copyright 2013-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.rugged.los;
18  
19  import java.util.stream.Stream;
20  
21  import org.hipparchus.analysis.differentiation.Derivative;
22  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23  import org.hipparchus.geometry.euclidean.threed.Vector3D;
24  import org.hipparchus.util.FastMath;
25  import org.orekit.rugged.utils.DerivativeGenerator;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.utils.ParameterDriver;
28  import org.orekit.utils.ParameterObserver;
29  import org.orekit.utils.TimeSpanMap;
30  
31  /** {@link TimeIndependentLOSTransform LOS transform} based on a homothety along the Z axis.
32   * @author Lucie Labatallee
33   * @author Guylaine Prat
34   * @see LOSBuilder
35   * @since 2.0
36   */
37  public class FixedZHomothety implements TimeIndependentLOSTransform {
38  
39      /** Parameters scaling factor.
40       * <p>
41       * We use a power of 2 to avoid numeric noise introduction
42       * in the multiplications/divisions sequences.
43       * </p>
44       */
45      private final double SCALE = FastMath.scalb(1.0, 0);
46  
47      /** Homothety factor. */
48      private double factor;
49  
50      /** Underlying homothety with derivatives. */
51      private Derivative<?> factorDS;
52  
53      /** Driver for homothety factor. */
54      private final ParameterDriver factorDriver;
55  
56      /** Simple constructor.
57       * <p>
58       * The single parameter is the homothety factor.
59       * </p>
60       * @param name name of the homothety (used for estimated parameters identification)
61       * @param factorvalue homothety factor
62       */
63      public FixedZHomothety(final String name, final double factorvalue) {
64  
65          this.factor   = factorvalue;
66          this.factorDS = null;
67          this.factorDriver = new ParameterDriver(name, factorvalue, SCALE, 0, Double.POSITIVE_INFINITY);
68          factorDriver.addObserver(new ParameterObserver() {
69              @Override
70              public void valueChanged(final double previousValue, final ParameterDriver driver, final AbsoluteDate date) {
71                  // reset factor to zero, they will be evaluated lazily if needed
72                  factor = 0.0;
73                  factorDS = null;
74              }
75  
76              @Override
77              public void valueSpanMapChanged(final TimeSpanMap<Double> previousValueSpanMap, final ParameterDriver driver) {
78                  // reset factor to zero, they will be evaluated lazily if needed
79                  factor = 0.0;
80                  factorDS = null;
81              }
82          });
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public Stream<ParameterDriver> getParametersDrivers() {
88          return Stream.of(factorDriver);
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      public Vector3D transformLOS(final int i, final Vector3D los) {
94  
95          if (factor == 0.0) {
96              // lazy evaluation of the homothety
97              factor = factorDriver.getValue();
98          }
99          return new Vector3D(los.getX(), los.getY(), factor * los.getZ());
100     }
101 
102     /** {@inheritDoc} */
103     @SuppressWarnings("unchecked")
104     @Override
105     public <T extends Derivative<T>> FieldVector3D<T> transformLOS(final int i, final FieldVector3D<T> los,
106                                                                    final DerivativeGenerator<T> generator) {
107         final T factorD;
108         if (factorDS == null || !factorDS.getField().equals(generator.getField())) {
109 
110             // lazy evaluation of the homothety
111             factorD = generator.variable(factorDriver);
112 
113             // cache evaluated homothety
114             factorDS = factorD;
115 
116         } else {
117             // reuse cached value
118             factorD  = (T) factorDS;
119         }
120 
121         return new FieldVector3D<>(los.getX(), los.getY(), factorD.multiply(los.getZ()));
122 
123     }
124 
125 }