AbstractEncounterLOF.java

  1. /* Copyright 2002-2024 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.frames.encounter;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.Field;
  20. import org.hipparchus.geometry.euclidean.threed.FieldRotation;
  21. import org.hipparchus.geometry.euclidean.threed.Rotation;
  22. import org.orekit.utils.FieldPVCoordinates;
  23. import org.orekit.utils.PVCoordinates;

  24. /**
  25.  * Abstract class for encounter frame between two objects.
  26.  *
  27.  * @author Vincent Cucchietti
  28.  * @since 12.0
  29.  */
  30. public abstract class AbstractEncounterLOF implements EncounterLOF {

  31.     /**
  32.      * Other position and velocity of the encounter frame. Can be null.
  33.      * <p>
  34.      * <b>BEWARE: This is not the origin of the encounter local orbital frame !</b>
  35.      */
  36.     private PVCoordinates other;

  37.     /**
  38.      * Other position and velocity of the encounter frame. Can be null.
  39.      * <p>
  40.      * <b>BEWARE: This is not the origin of the encounter local orbital frame !</b>
  41.      */
  42.     private FieldPVCoordinates<?> fieldOther;

  43.     /**
  44.      * Constructor with {@link PVCoordinates}.
  45.      *
  46.      * @param other other object to create the encounter local orbital frame with (<b>not</b> the origin of the frame !)
  47.      */
  48.     protected AbstractEncounterLOF(final PVCoordinates other) {
  49.         this.other = other;
  50.     }

  51.     /**
  52.      * Constructor with {@link FieldPVCoordinates}.
  53.      *
  54.      * @param other other object to create the encounter frame with (<b>not</b> the origin of the frame !)
  55.      * @param <T> type of the field elements
  56.      */
  57.     protected <T extends CalculusFieldElement<T>> AbstractEncounterLOF(final FieldPVCoordinates<T> other) {
  58.         this.fieldOther = other;
  59.     }

  60.     /**
  61.      * Get the rotation from inertial to this encounter local orbital frame.
  62.      * <p>
  63.      * <b>BEWARE: The given origin's position and velocity coordinates must be given in the frame in which this instance
  64.      * has been expressed in.</b>
  65.      *
  66.      * @param field field to which the elements belong
  67.      * @param origin position-velocity of the origin in the same inertial frame as the one this instance has been expressed
  68.      * in.
  69.      * @param <T> type of the field elements
  70.      *
  71.      * @return rotation from inertial to this encounter local orbital frame
  72.      */
  73.     public <T extends CalculusFieldElement<T>> FieldRotation<T> rotationFromInertial(final Field<T> field,
  74.                                                                                      final FieldPVCoordinates<T> origin) {
  75.         return rotationFromInertial(field, origin, getFieldOther(field));
  76.     }

  77.     /**
  78.      * Get the rotation from inertial to this encounter local orbital frame.
  79.      * <p>
  80.      * <b>BEWARE: The given origin's position and velocity coordinates must be given in the frame in which this instance
  81.      * has been expressed in.</b>
  82.      *
  83.      * @param origin position-velocity of the origin in some inertial frame
  84.      *
  85.      * @return rotation from inertial to this encounter local orbital frame
  86.      */
  87.     public Rotation rotationFromInertial(final PVCoordinates origin) {
  88.         return rotationFromInertial(origin, getOther());
  89.     }

  90.     /**
  91.      * Get the field version of other's position and velocity coordinates. If the instance has been created with normal
  92.      * {@link PVCoordinates}, then it will build its field equivalent.
  93.      *
  94.      * @param field field of the elements
  95.      * @param <T> type of the field elements
  96.      *
  97.      * @return field version of other's position and velocity coordinates
  98.      */
  99.     @SuppressWarnings("unchecked")
  100.     @Override
  101.     public <T extends CalculusFieldElement<T>> FieldPVCoordinates<T> getFieldOther(final Field<T> field) {
  102.         return fieldOther == null ? new FieldPVCoordinates<>(field, other) : (FieldPVCoordinates<T>) fieldOther;
  103.     }

  104.     /**
  105.      * Get the normal version of other's position and velocity coordinates. If the instance has been created with field
  106.      * {@link FieldPVCoordinates}, then it will convert it to its {@link PVCoordinates} equivalent.
  107.      *
  108.      * @return normal version of other's position and velocity coordinates
  109.      */
  110.     @Override
  111.     public PVCoordinates getOther() {
  112.         return other == null ? fieldOther.toPVCoordinates() : other;
  113.     }
  114. }