TimeStampedFieldAngularCoordinates.java

  1. /* Copyright 2002-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.utils;


  18. import org.hipparchus.Field;
  19. import org.hipparchus.CalculusFieldElement;
  20. import org.hipparchus.analysis.differentiation.FieldDerivative;
  21. import org.hipparchus.analysis.differentiation.FieldDerivativeStructure;
  22. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  23. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  24. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.time.FieldTimeStamped;
  28. import org.orekit.time.TimeStamped;

  29. /** {@link TimeStamped time-stamped} version of {@link FieldAngularCoordinates}.
  30.  * <p>Instances of this class are guaranteed to be immutable.</p>
  31.  * @param <T> the type of the field elements
  32.  * @author Luc Maisonobe
  33.  * @since 7.0
  34.  */
  35. public class TimeStampedFieldAngularCoordinates<T extends CalculusFieldElement<T>>
  36.     extends FieldAngularCoordinates<T> implements FieldTimeStamped<T> {

  37.     /** The date. */
  38.     private final FieldAbsoluteDate<T> date;

  39.     /** Build the rotation that transforms a pair of pv coordinates into another pair.

  40.      * <p><em>WARNING</em>! This method requires much more stringent assumptions on
  41.      * its parameters than the similar {@link org.hipparchus.geometry.euclidean.threed.Rotation#Rotation(
  42.      * org.hipparchus.geometry.euclidean.threed.Vector3D, org.hipparchus.geometry.euclidean.threed.Vector3D,
  43.      * org.hipparchus.geometry.euclidean.threed.Vector3D, org.hipparchus.geometry.euclidean.threed.Vector3D)
  44.      * constructor} from the {@link org.hipparchus.geometry.euclidean.threed.Rotation Rotation} class.
  45.      * As far as the Rotation constructor is concerned, the {@code v₂} vector from
  46.      * the second pair can be slightly misaligned. The Rotation constructor will
  47.      * compensate for this misalignment and create a rotation that ensure {@code
  48.      * v₁ = r(u₁)} and {@code v₂ ∈ plane (r(u₁), r(u₂))}. <em>THIS IS NOT
  49.      * TRUE ANYMORE IN THIS CLASS</em>! As derivatives are involved and must be
  50.      * preserved, this constructor works <em>only</em> if the two pairs are fully
  51.      * consistent, i.e. if a rotation exists that fulfill all the requirements: {@code
  52.      * v₁ = r(u₁)}, {@code v₂ = r(u₂)}, {@code dv₁/dt = dr(u₁)/dt}, {@code dv₂/dt
  53.      * = dr(u₂)/dt}, {@code d²v₁/dt² = d²r(u₁)/dt²}, {@code d²v₂/dt² = d²r(u₂)/dt²}.</p>

  54.      * @param date coordinates date
  55.      * @param u1 first vector of the origin pair
  56.      * @param u2 second vector of the origin pair
  57.      * @param v1 desired image of u1 by the rotation
  58.      * @param v2 desired image of u2 by the rotation
  59.      * @param tolerance relative tolerance factor used to check singularities
  60.      */
  61.     public TimeStampedFieldAngularCoordinates (final AbsoluteDate date,
  62.                                                final FieldPVCoordinates<T> u1, final FieldPVCoordinates<T> u2,
  63.                                                final FieldPVCoordinates<T> v1, final FieldPVCoordinates<T> v2,
  64.                                                final double tolerance) {
  65.         this(new FieldAbsoluteDate<>(u1.getPosition().getX().getField(), date),
  66.              u1, u2, v1, v2, tolerance);
  67.     }

  68.     /** Build the rotation that transforms a pair of pv coordinates into another pair.

  69.      * <p><em>WARNING</em>! This method requires much more stringent assumptions on
  70.      * its parameters than the similar {@link org.hipparchus.geometry.euclidean.threed.Rotation#Rotation(
  71.      * org.hipparchus.geometry.euclidean.threed.Vector3D, org.hipparchus.geometry.euclidean.threed.Vector3D,
  72.      * org.hipparchus.geometry.euclidean.threed.Vector3D, org.hipparchus.geometry.euclidean.threed.Vector3D)
  73.      * constructor} from the {@link org.hipparchus.geometry.euclidean.threed.Rotation Rotation} class.
  74.      * As far as the Rotation constructor is concerned, the {@code v₂} vector from
  75.      * the second pair can be slightly misaligned. The Rotation constructor will
  76.      * compensate for this misalignment and create a rotation that ensure {@code
  77.      * v₁ = r(u₁)} and {@code v₂ ∈ plane (r(u₁), r(u₂))}. <em>THIS IS NOT
  78.      * TRUE ANYMORE IN THIS CLASS</em>! As derivatives are involved and must be
  79.      * preserved, this constructor works <em>only</em> if the two pairs are fully
  80.      * consistent, i.e. if a rotation exists that fulfill all the requirements: {@code
  81.      * v₁ = r(u₁)}, {@code v₂ = r(u₂)}, {@code dv₁/dt = dr(u₁)/dt}, {@code dv₂/dt
  82.      * = dr(u₂)/dt}, {@code d²v₁/dt² = d²r(u₁)/dt²}, {@code d²v₂/dt² = d²r(u₂)/dt²}.</p>

  83.      * @param date coordinates date
  84.      * @param u1 first vector of the origin pair
  85.      * @param u2 second vector of the origin pair
  86.      * @param v1 desired image of u1 by the rotation
  87.      * @param v2 desired image of u2 by the rotation
  88.      * @param tolerance relative tolerance factor used to check singularities
  89.      */
  90.     public TimeStampedFieldAngularCoordinates (final FieldAbsoluteDate<T> date,
  91.                                                final FieldPVCoordinates<T> u1, final FieldPVCoordinates<T> u2,
  92.                                                final FieldPVCoordinates<T> v1, final FieldPVCoordinates<T> v2,
  93.                                                final double tolerance) {
  94.         super(u1, u2, v1, v2, tolerance);
  95.         this.date = date;
  96.     }

  97.     /** Builds a rotation/rotation rate pair.
  98.      * @param date coordinates date
  99.      * @param rotation rotation
  100.      * @param rotationRate rotation rate Ω (rad/s)
  101.      * @param rotationAcceleration rotation acceleration dΩ/dt (rad²/s²)
  102.      */
  103.     public TimeStampedFieldAngularCoordinates(final AbsoluteDate date,
  104.                                               final FieldRotation<T> rotation,
  105.                                               final FieldVector3D<T> rotationRate,
  106.                                               final FieldVector3D<T> rotationAcceleration) {
  107.         this(new FieldAbsoluteDate<>(rotation.getQ0().getField(), date),
  108.              rotation, rotationRate, rotationAcceleration);
  109.     }

  110.     /** Builds a rotation/rotation rate pair.
  111.      * @param date coordinates date
  112.      * @param rotation rotation
  113.      * @param rotationRate rotation rate Ω (rad/s)
  114.      * @param rotationAcceleration rotation acceleration dΩ/dt (rad²/s²)
  115.      */
  116.     public TimeStampedFieldAngularCoordinates(final FieldAbsoluteDate<T> date,
  117.                                               final FieldRotation<T> rotation,
  118.                                               final FieldVector3D<T> rotationRate,
  119.                                               final FieldVector3D<T> rotationAcceleration) {
  120.         super(rotation, rotationRate, rotationAcceleration);
  121.         this.date = date;
  122.     }

  123.     /** Builds an instance for a regular {@link TimeStampedAngularCoordinates}.
  124.      * @param field fields to which the elements belong
  125.      * @param ac coordinates to convert
  126.      * @since 9.0
  127.      */
  128.     public TimeStampedFieldAngularCoordinates(final Field<T> field,
  129.                                               final TimeStampedAngularCoordinates ac) {
  130.         this(new FieldAbsoluteDate<>(field, ac.getDate()),
  131.              new FieldRotation<>(field, ac.getRotation()),
  132.              new FieldVector3D<>(field, ac.getRotationRate()),
  133.              new FieldVector3D<>(field, ac.getRotationAcceleration()));
  134.     }

  135.     /** Builds a TimeStampedFieldAngularCoordinates from  a {@link FieldRotation}&lt;{@link FieldDerivativeStructure}&gt;.
  136.      * <p>
  137.      * The rotation components must have time as their only derivation parameter and
  138.      * have consistent derivation orders.
  139.      * </p>
  140.      * @param date coordinates date
  141.      * @param r rotation with time-derivatives embedded within the coordinates
  142.      * @param <U> type of the derivative
  143.      * @since 9.2
  144.      */
  145.     public <U extends FieldDerivative<T, U>> TimeStampedFieldAngularCoordinates(final FieldAbsoluteDate<T> date,
  146.                                                                                 final FieldRotation<U> r) {
  147.         super(r);
  148.         this.date = date;
  149.     }

  150.     /** Revert a rotation/rotation rate pair.
  151.      * Build a pair which reverse the effect of another pair.
  152.      * @return a new pair whose effect is the reverse of the effect
  153.      * of the instance
  154.      */
  155.     public TimeStampedFieldAngularCoordinates<T> revert() {
  156.         return new TimeStampedFieldAngularCoordinates<>(date,
  157.                                                         getRotation().revert(),
  158.                                                         getRotation().applyInverseTo(getRotationRate().negate()),
  159.                                                         getRotation().applyInverseTo(getRotationAcceleration().negate()));
  160.     }

  161.     /** {@inheritDoc} */
  162.     @Override
  163.     public FieldAbsoluteDate<T> getDate() {
  164.         return date;
  165.     }

  166.     /** Get a time-shifted state.
  167.      * <p>
  168.      * The state can be slightly shifted to close dates. This shift is based on
  169.      * a simple linear model. It is <em>not</em> intended as a replacement for
  170.      * proper attitude propagation but should be sufficient for either small
  171.      * time shifts or coarse accuracy.
  172.      * </p>
  173.      * @param dt time shift in seconds
  174.      * @return a new state, shifted with respect to the instance (which is immutable)
  175.      */
  176.     public TimeStampedFieldAngularCoordinates<T> shiftedBy(final double dt) {
  177.         return shiftedBy(getDate().getField().getZero().newInstance(dt));
  178.     }

  179.     /** Get a time-shifted state.
  180.      * <p>
  181.      * The state can be slightly shifted to close dates. This shift is based on
  182.      * a simple linear model. It is <em>not</em> intended as a replacement for
  183.      * proper attitude propagation but should be sufficient for either small
  184.      * time shifts or coarse accuracy.
  185.      * </p>
  186.      * @param dt time shift in seconds
  187.      * @return a new state, shifted with respect to the instance (which is immutable)
  188.      */
  189.     public TimeStampedFieldAngularCoordinates<T> shiftedBy(final T dt) {
  190.         final FieldAngularCoordinates<T> sac = super.shiftedBy(dt);
  191.         return new TimeStampedFieldAngularCoordinates<>(date.shiftedBy(dt),
  192.                                                         sac.getRotation(), sac.getRotationRate(), sac.getRotationAcceleration());

  193.     }

  194.     /** Add an offset from the instance.
  195.      * <p>
  196.      * We consider here that the offset rotation is applied first and the
  197.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  198.      * commute under this operation, i.e. {@code a.addOffset(b)} and {@code
  199.      * b.addOffset(a)} lead to <em>different</em> results in most cases.
  200.      * </p>
  201.      * <p>
  202.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  203.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  204.      * so that round trip applications are possible. This means that both {@code
  205.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  206.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  207.      * </p>
  208.      * @param offset offset to subtract
  209.      * @return new instance, with offset subtracted
  210.      * @see #subtractOffset(FieldAngularCoordinates)
  211.      */
  212.     public TimeStampedFieldAngularCoordinates<T> addOffset(final FieldAngularCoordinates<T> offset) {
  213.         final FieldVector3D<T> rOmega    = getRotation().applyTo(offset.getRotationRate());
  214.         final FieldVector3D<T> rOmegaDot = getRotation().applyTo(offset.getRotationAcceleration());
  215.         return new TimeStampedFieldAngularCoordinates<>(date,
  216.                                                         getRotation().compose(offset.getRotation(), RotationConvention.VECTOR_OPERATOR),
  217.                                                         getRotationRate().add(rOmega),
  218.                                                         new FieldVector3D<>( 1.0, getRotationAcceleration(),
  219.                                                                               1.0, rOmegaDot,
  220.                                                                              -1.0, FieldVector3D.crossProduct(getRotationRate(), rOmega)));
  221.     }

  222.     /** Subtract an offset from the instance.
  223.      * <p>
  224.      * We consider here that the offset Rotation is applied first and the
  225.      * instance is applied afterward. Note that angular coordinates do <em>not</em>
  226.      * commute under this operation, i.e. {@code a.subtractOffset(b)} and {@code
  227.      * b.subtractOffset(a)} lead to <em>different</em> results in most cases.
  228.      * </p>
  229.      * <p>
  230.      * The two methods {@link #addOffset(FieldAngularCoordinates) addOffset} and
  231.      * {@link #subtractOffset(FieldAngularCoordinates) subtractOffset} are designed
  232.      * so that round trip applications are possible. This means that both {@code
  233.      * ac1.subtractOffset(ac2).addOffset(ac2)} and {@code
  234.      * ac1.addOffset(ac2).subtractOffset(ac2)} return angular coordinates equal to ac1.
  235.      * </p>
  236.      * @param offset offset to subtract
  237.      * @return new instance, with offset subtracted
  238.      * @see #addOffset(FieldAngularCoordinates)
  239.      */
  240.     public TimeStampedFieldAngularCoordinates<T> subtractOffset(final FieldAngularCoordinates<T> offset) {
  241.         return addOffset(offset.revert());
  242.     }

  243. }