TrajectoryState.java

  1. /* Copyright 2002-2022 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.files.ccsds.definitions.ElementsType;
  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 ElementsType 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
  41.      * @param units units to use for parsing
  42.      */
  43.     public TrajectoryState(final ElementsType 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.     /** {@inheritDoc} */
  53.     @Override
  54.     public AbsoluteDate getDate() {
  55.         return date;
  56.     }

  57.     /** Get trajectory elements.
  58.      * @return trajectory elements
  59.      */
  60.     public double[] getElements() {
  61.         return elements.clone();
  62.     }

  63.     /** Get the type of the elements.
  64.      * @return type of the elements
  65.      */
  66.     public ElementsType getType() {
  67.         return type;
  68.     }

  69.     /** Get which derivatives of position are available in this state.
  70.      * @return a value indicating if the file contains velocity and/or acceleration
  71.       */
  72.     public CartesianDerivativesFilter getAvailableDerivatives() {
  73.         return type ==  ElementsType.CARTP ?
  74.                         CartesianDerivativesFilter.USE_P :
  75.                         (type == ElementsType.CARTPVA ?
  76.                          CartesianDerivativesFilter.USE_PVA :
  77.                          CartesianDerivativesFilter.USE_PV);
  78.     }

  79.     /** Convert to Cartesian coordinates.
  80.      * @param mu gravitational parameter in m³/s²
  81.      * @return Cartesian coordinates
  82.      */
  83.     public TimeStampedPVCoordinates toCartesian(final double mu) {
  84.         return type.toCartesian(date, elements, mu);
  85.     }

  86. }