StateVector.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;

  18. import java.util.Arrays;

  19. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.files.ccsds.section.CommentsContainer;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.utils.TimeStampedPVCoordinates;

  25. /** Container for state vector data.
  26.  * <p>
  27.  * Beware that the Orekit getters and setters all rely on SI units. The parsers
  28.  * and writers take care of converting these SI units into CCSDS mandatory units.
  29.  * The {@link org.orekit.utils.units.Unit Unit} class provides useful
  30.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  31.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
  32.  * already use CCSDS units instead of the API SI units. The general-purpose
  33.  * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
  34.  * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
  35.  * (with an 's') also provide some predefined units. These predefined units and the
  36.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  37.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
  38.  * what the parsers and writers use for the conversions.
  39.  * </p>
  40.  * @author Luc Maisonobe
  41.  * @since 11.0
  42.  */
  43. public class StateVector extends CommentsContainer {

  44.     /** Epoch of state vector and optional Keplerian elements. */
  45.     private AbsoluteDate epoch;

  46.     /** Position vector (m). */
  47.     private final double[] position;

  48.     /** Velocity vector (m/s). */
  49.     private final double[] velocity;

  50.     /** Acceleration vector (m/s²). */
  51.     private final double[] acceleration;

  52.     /** Create an empty data set.
  53.      */
  54.     public StateVector() {
  55.         position     = new double[3];
  56.         velocity     = new double[3];
  57.         acceleration = new double[3];
  58.         Arrays.fill(position,     Double.NaN);
  59.         Arrays.fill(velocity,     Double.NaN);
  60.         Arrays.fill(acceleration, Double.NaN);
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public void validate(final double version) {
  65.         super.validate(version);
  66.         checkNotNull(epoch, StateVectorKey.EPOCH.name());
  67.         if (Double.isNaN(position[0] + position[1] + position[2])) {
  68.             throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}");
  69.         }
  70.         if (Double.isNaN(velocity[0] + velocity[1] + velocity[2])) {
  71.             throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}_DOT");
  72.         }
  73.     }

  74.     /** Get epoch of state vector, Keplerian elements and covariance matrix data.
  75.      * @return epoch the epoch
  76.      */
  77.     public AbsoluteDate getEpoch() {
  78.         return epoch;
  79.     }

  80.     /** Set epoch of state vector, Keplerian elements and covariance matrix data.
  81.      * @param epoch the epoch to be set
  82.      */
  83.     public void setEpoch(final AbsoluteDate epoch) {
  84.         refuseFurtherComments();
  85.         this.epoch = epoch;
  86.     }

  87.     /**
  88.      * Set position component.
  89.      * @param index component index (counting from 0)
  90.      * @param value position component
  91.      */
  92.     public void setP(final int index, final double value) {
  93.         refuseFurtherComments();
  94.         position[index] = value;
  95.     }

  96.     /**
  97.      * Set velocity component.
  98.      * @param index component index (counting from 0)
  99.      * @param value velocity component
  100.      */
  101.     public void setV(final int index, final double value) {
  102.         refuseFurtherComments();
  103.         velocity[index] = value;
  104.     }

  105.     /**
  106.      * Set acceleration component.
  107.      * @param index component index (counting from 0)
  108.      * @param value acceleration component
  109.      */
  110.     public void setA(final int index, final double value) {
  111.         refuseFurtherComments();
  112.         acceleration[index] = value;
  113.     }

  114.     /** Check if state contains acceleration data.
  115.      * @return true is state contains acceleration data
  116.      */
  117.     public boolean hasAcceleration() {
  118.         return !Double.isNaN(acceleration[0] + acceleration[1] + acceleration[2]);
  119.     }

  120.     /** Convert to {@link TimeStampedPVCoordinates}.
  121.      * @return a new {@link TimeStampedPVCoordinates}
  122.      */
  123.     public TimeStampedPVCoordinates toTimeStampedPVCoordinates() {
  124.         return new TimeStampedPVCoordinates(epoch,
  125.                                             new Vector3D(position),
  126.                                             new Vector3D(velocity),
  127.                                             hasAcceleration() ? new Vector3D(acceleration) : Vector3D.ZERO);
  128.     }

  129. }