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  
18  package org.orekit.files.ccsds.ndm.odm;
19  
20  import java.util.Arrays;
21  
22  import org.hipparchus.geometry.euclidean.threed.Vector3D;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.files.ccsds.section.CommentsContainer;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.utils.TimeStampedPVCoordinates;
28  
29  /** Container for state vector data.
30   * @author Luc Maisonobe
31   * @since 11.0
32   */
33  public class StateVector extends CommentsContainer {
34  
35      /** Epoch of state vector and optional Keplerian elements. */
36      private AbsoluteDate epoch;
37  
38      /** Position vector (m). */
39      private double[] position;
40  
41      /** Velocity vector (m/s). */
42      private double[] velocity;
43  
44      /** Accekeration vector (m/s²). */
45      private double[] acceleration;
46  
47      /** Create an empty data set.
48       */
49      public StateVector() {
50          position     = new double[3];
51          velocity     = new double[3];
52          acceleration = new double[3];
53          Arrays.fill(position,     Double.NaN);
54          Arrays.fill(velocity,     Double.NaN);
55          Arrays.fill(acceleration, Double.NaN);
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public void validate(final double version) {
61          super.validate(version);
62          checkNotNull(epoch, StateVectorKey.EPOCH.name());
63          if (Double.isNaN(position[0] + position[1] + position[2])) {
64              throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}");
65          }
66          if (Double.isNaN(velocity[0] + velocity[1] + velocity[2])) {
67              throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, "{X|Y|Z}_DOT");
68          }
69      }
70  
71      /** Get epoch of state vector, Keplerian elements and covariance matrix data.
72       * @return epoch the epoch
73       */
74      public AbsoluteDate getEpoch() {
75          return epoch;
76      }
77  
78      /** Set epoch of state vector, Keplerian elements and covariance matrix data.
79       * @param epoch the epoch to be set
80       */
81      public void setEpoch(final AbsoluteDate epoch) {
82          refuseFurtherComments();
83          this.epoch = epoch;
84      }
85  
86      /**
87       * Set position component.
88       * @param index component index (counting from 0)
89       * @param value position component
90       */
91      public void setP(final int index, final double value) {
92          refuseFurtherComments();
93          position[index] = value;
94      }
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     /**
107      * Set acceleration component.
108      * @param index component index (counting from 0)
109      * @param value acceleration component
110      */
111     public void setA(final int index, final double value) {
112         refuseFurtherComments();
113         acceleration[index] = value;
114     }
115 
116     /** Check if state contains acceleration data.
117      * @return true is state contains acceleration data
118      */
119     public boolean hasAcceleration() {
120         return !Double.isNaN(acceleration[0] + acceleration[1] + acceleration[2]);
121     }
122 
123     /** Convert to {@link TimeStampedPVCoordinates}.
124      * @return a new {@link TimeStampedPVCoordinates}
125      */
126     public TimeStampedPVCoordinates toTimeStampedPVCoordinates() {
127         return new TimeStampedPVCoordinates(epoch,
128                                             new Vector3D(position),
129                                             new Vector3D(velocity),
130                                             hasAcceleration() ? new Vector3D(acceleration) : Vector3D.ZERO);
131     }
132 
133 }
134