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