TrajectoryState.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.files.ccsds.ndm.odm.ocm;

  18. import java.util.List;

  19. import org.orekit.bodies.OneAxisEllipsoid;
  20. import org.orekit.time.AbsoluteDate;
  21. import org.orekit.time.TimeStamped;
  22. import org.orekit.utils.CartesianDerivativesFilter;
  23. import org.orekit.utils.TimeStampedPVCoordinates;
  24. import org.orekit.utils.units.Unit;

  25. /** Trajectory state entry.
  26.  * @author Luc Maisonobe
  27.  * @since 11.0
  28.  */
  29. public class TrajectoryState implements TimeStamped {

  30.     /** Type of the elements. */
  31.     private final OrbitElementsType type;

  32.     /** Entry date. */
  33.     private final AbsoluteDate date;

  34.     /** Trajectory elements. */
  35.     private final double[] elements;

  36.     /** Simple constructor.
  37.      * @param type type of the elements
  38.      * @param date entry date
  39.      * @param fields trajectory elements
  40.      * @param first index of first field to consider when parsing
  41.      * @param units units to use for parsing
  42.      */
  43.     public TrajectoryState(final OrbitElementsType type, final AbsoluteDate date,
  44.                            final String[] fields, final int first, final List<Unit> units) {
  45.         this.type     = type;
  46.         this.date     = date;
  47.         this.elements = new double[units.size()];
  48.         for (int i = 0; i < elements.length; ++i) {
  49.             elements[i] = units.get(i).toSI(Double.parseDouble(fields[first + i]));
  50.         }
  51.     }

  52.     /** Simple constructor.
  53.      * @param type type of the elements
  54.      * @param date entry date
  55.      * @param elements trajectory elements in SI units
  56.      * @since 12.0
  57.      */
  58.     public TrajectoryState(final OrbitElementsType type, final AbsoluteDate date,
  59.                            final double[] elements) {
  60.         this.type     = type;
  61.         this.date     = date;
  62.         this.elements = elements.clone();
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public AbsoluteDate getDate() {
  67.         return date;
  68.     }

  69.     /** Get trajectory elements.
  70.      * @return trajectory elements
  71.      */
  72.     public double[] getElements() {
  73.         return elements.clone();
  74.     }

  75.     /** Get the type of the elements.
  76.      * @return type of the elements
  77.      */
  78.     public OrbitElementsType getType() {
  79.         return type;
  80.     }

  81.     /** Get which derivatives of position are available in this state.
  82.      * @return a value indicating if the file contains velocity and/or acceleration
  83.       */
  84.     public CartesianDerivativesFilter getAvailableDerivatives() {
  85.         return type ==  OrbitElementsType.CARTP ?
  86.                         CartesianDerivativesFilter.USE_P :
  87.                         (type == OrbitElementsType.CARTPVA ?
  88.                          CartesianDerivativesFilter.USE_PVA :
  89.                          CartesianDerivativesFilter.USE_PV);
  90.     }

  91.     /** Convert to Cartesian coordinates.
  92.      * @param body central body
  93.      * (may be null if {@link #getType() type} is <em>not</em> {@link OrbitElementsType#GEODETIC})
  94.      * @param mu gravitational parameter in m³/s²
  95.      * @return Cartesian coordinates
  96.      */
  97.     public TimeStampedPVCoordinates toCartesian(final OneAxisEllipsoid body, final double mu) {
  98.         return type.toCartesian(date, elements, body, mu);
  99.     }

  100. }