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

  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.  * @author Luc Maisonobe
  27.  * @since 11.0
  28.  */
  29. public class StateVector extends CommentsContainer {

  30.     /** Epoch of state vector and optional Keplerian elements. */
  31.     private AbsoluteDate epoch;

  32.     /** Position vector (m). */
  33.     private double[] position;

  34.     /** Velocity vector (m/s). */
  35.     private double[] velocity;

  36.     /** Accekeration vector (m/s²). */
  37.     private double[] acceleration;

  38.     /** Create an empty data set.
  39.      */
  40.     public StateVector() {
  41.         position     = new double[3];
  42.         velocity     = new double[3];
  43.         acceleration = new double[3];
  44.         Arrays.fill(position,     Double.NaN);
  45.         Arrays.fill(velocity,     Double.NaN);
  46.         Arrays.fill(acceleration, Double.NaN);
  47.     }

  48.     /** {@inheritDoc} */
  49.     @Override
  50.     public void validate(final double version) {
  51.         super.validate(version);
  52.         checkNotNull(epoch, StateVectorKey.EPOCH);
  53.         if (Double.isNaN(position[0] + position[1] + position[2])) {
  54.             throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}");
  55.         }
  56.         if (Double.isNaN(velocity[0] + velocity[1] + velocity[2])) {
  57.             throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}_DOT");
  58.         }
  59.     }

  60.     /** Get epoch of state vector, Keplerian elements and covariance matrix data.
  61.      * @return epoch the epoch
  62.      */
  63.     public AbsoluteDate getEpoch() {
  64.         return epoch;
  65.     }

  66.     /** Set epoch of state vector, Keplerian elements and covariance matrix data.
  67.      * @param epoch the epoch to be set
  68.      */
  69.     public void setEpoch(final AbsoluteDate epoch) {
  70.         refuseFurtherComments();
  71.         this.epoch = epoch;
  72.     }

  73.     /**
  74.      * Set position component.
  75.      * @param index component index (counting from 0)
  76.      * @param value position component
  77.      */
  78.     public void setP(final int index, final double value) {
  79.         refuseFurtherComments();
  80.         position[index] = value;
  81.     }

  82.     /**
  83.      * Set velocity component.
  84.      * @param index component index (counting from 0)
  85.      * @param value velocity component
  86.      */
  87.     public void setV(final int index, final double value) {
  88.         refuseFurtherComments();
  89.         velocity[index] = value;
  90.     }

  91.     /**
  92.      * Set acceleration component.
  93.      * @param index component index (counting from 0)
  94.      * @param value acceleration component
  95.      */
  96.     public void setA(final int index, final double value) {
  97.         refuseFurtherComments();
  98.         acceleration[index] = value;
  99.     }

  100.     /** Check if state contains acceleration data.
  101.      * @return true is state contains acceleration data
  102.      */
  103.     public boolean hasAcceleration() {
  104.         return !Double.isNaN(acceleration[0] + acceleration[1] + acceleration[2]);
  105.     }

  106.     /** Convert to {@link TimeStampedPVCoordinates}.
  107.      * @return a new {@link TimeStampedPVCoordinates}
  108.      */
  109.     public TimeStampedPVCoordinates toTimeStampedPVCoordinates() {
  110.         return new TimeStampedPVCoordinates(epoch,
  111.                                             new Vector3D(position),
  112.                                             new Vector3D(velocity),
  113.                                             hasAcceleration() ? new Vector3D(acceleration) : Vector3D.ZERO);
  114.     }

  115. }