FixedRotation.java

  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. import java.util.stream.Stream;

  19. import org.hipparchus.analysis.differentiation.Derivative;
  20. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  21. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  22. import org.hipparchus.geometry.euclidean.threed.Rotation;
  23. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  24. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  25. import org.hipparchus.util.FastMath;
  26. import org.orekit.rugged.utils.DerivativeGenerator;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.ParameterDriver;
  29. import org.orekit.utils.ParameterObserver;
  30. import org.orekit.utils.TimeSpanMap;

  31. /** {@link TimeIndependentLOSTransform LOS transform} based on a fixed rotation.
  32.  * @author Luc Maisonobe
  33.  * @see LOSBuilder
  34.  */
  35. public class FixedRotation 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, -20);

  43.     /** Rotation axis. */
  44.     private final Vector3D axis;

  45.     /** Underlying rotation. */
  46.     private Rotation rotation;

  47.     /** Underlying rotation with derivatives. */
  48.     private FieldRotation<?> rDS;

  49.     /** Driver for rotation angle. */
  50.     private final ParameterDriver angleDriver;

  51.     /** Simple constructor.
  52.      * <p>
  53.      * The single parameter is the rotation angle.
  54.      * </p>
  55.      * @param name name of the rotation (used for estimated parameters identification)
  56.      * @param axis rotation axis
  57.      * @param angle rotation angle
  58.      */
  59.     public FixedRotation(final String name, final Vector3D axis, final double angle) {

  60.         this.axis     = axis;
  61.         this.rotation = null;
  62.         this.rDS      = null;
  63.         this.angleDriver = new ParameterDriver(name, angle, SCALE, -2 * FastMath.PI, 2 * FastMath.PI);
  64.         angleDriver.addObserver(new ParameterObserver() {
  65.             @Override
  66.             public void valueChanged(final double previousValue, final ParameterDriver driver, final AbsoluteDate date) {
  67.                 // reset rotations to null, they will be evaluated lazily if needed
  68.                 rotation = null;
  69.                 rDS      = null;
  70.             }

  71.             @Override
  72.             public void valueSpanMapChanged(final TimeSpanMap<Double> previousValueSpanMap, final ParameterDriver driver) {
  73.                 // reset rotations to null, they will be evaluated lazily if needed
  74.                 rotation = null;
  75.                 rDS      = null;
  76.             }
  77.         });
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public Stream<ParameterDriver> getParametersDrivers() {
  82.         return Stream.of(angleDriver);
  83.     }

  84.     /** {@inheritDoc} */
  85.     @Override
  86.     public Vector3D transformLOS(final int i, final Vector3D los) {
  87.         if (rotation == null) {
  88.             // lazy evaluation of the rotation
  89.             rotation = new Rotation(axis, angleDriver.getValue(), RotationConvention.VECTOR_OPERATOR);
  90.         }
  91.         return rotation.applyTo(los);
  92.     }

  93.     /** {@inheritDoc} */
  94.     @SuppressWarnings("unchecked")
  95.     @Override
  96.     public <T extends Derivative<T>> FieldVector3D<T> transformLOS(final int i, final FieldVector3D<T> los,
  97.                                                                    final DerivativeGenerator<T> generator) {
  98.         final FieldRotation<T> rD;
  99.         if (rDS == null || !rDS.getQ0().getField().equals(generator.getField())) {

  100.             // lazy evaluation of the rotation
  101.             final FieldVector3D<T> axisDS =
  102.                             new FieldVector3D<>(generator.constant(axis.getX()),
  103.                                                 generator.constant(axis.getY()),
  104.                                                 generator.constant(axis.getZ()));
  105.             final T angleDS = generator.variable(angleDriver);
  106.             rD = new FieldRotation<>(axisDS, angleDS, RotationConvention.VECTOR_OPERATOR);

  107.             // cache evaluated rotation
  108.             rDS = rD;

  109.         } else {
  110.             // reuse cached value
  111.             rD  = (FieldRotation<T>) rDS;
  112.         }

  113.         return rD.applyTo(los);

  114.     }

  115. }