TrajectoryStateHistory.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.Collections;
  19. import java.util.List;
  20. import java.util.stream.Collectors;

  21. import org.orekit.bodies.OneAxisEllipsoid;
  22. import org.orekit.errors.OrekitException;
  23. import org.orekit.errors.OrekitMessages;
  24. import org.orekit.files.general.EphemerisFile;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.CartesianDerivativesFilter;
  28. import org.orekit.utils.TimeStampedPVCoordinates;

  29. /** Trajectory state history.
  30.  * @author Luc Maisonobe
  31.  * @since 11.0
  32.  */
  33. public class TrajectoryStateHistory implements EphemerisFile.EphemerisSegment<TimeStampedPVCoordinates> {

  34.     /** Metadata. */
  35.     private final TrajectoryStateHistoryMetadata metadata;

  36.     /** Trajectory states. */
  37.     private final List<TrajectoryState> states;

  38.     /** Gravitational parameter in m³/s². */
  39.     private final double mu;

  40.     /** Central body.
  41.      * @since 12.0
  42.      */
  43.     private final OneAxisEllipsoid body;

  44.     /** Simple constructor.
  45.      * @param metadata metadata
  46.      * @param states orbital states
  47.      * @param body central body (may be null if {@link TrajectoryStateHistoryMetadata#getTrajType() type}
  48.      * is <em>not</em> {@link OrbitElementsType#GEODETIC})
  49.      * @param mu gravitational parameter in m³/s²
  50.      */
  51.     public TrajectoryStateHistory(final TrajectoryStateHistoryMetadata metadata,
  52.                                   final List<TrajectoryState> states,
  53.                                   final OneAxisEllipsoid body, final double mu) {
  54.         this.metadata = metadata;
  55.         this.states   = states;
  56.         this.mu       = mu;
  57.         this.body     = body;
  58.     }

  59.     /** Get metadata.
  60.      * @return metadata
  61.      */
  62.     public TrajectoryStateHistoryMetadata getMetadata() {
  63.         return metadata;
  64.     }

  65.     /** Get the trajectory states.
  66.      * @return trajectory states
  67.      */
  68.     public List<TrajectoryState> getTrajectoryStates() {
  69.         return Collections.unmodifiableList(states);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public double getMu() {
  74.         return mu;
  75.     }

  76.     /** Get central body.
  77.      * @return central body
  78.      * @since 12.0
  79.      */
  80.     public OneAxisEllipsoid getBody() {
  81.         return body;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     public Frame getFrame() {
  86.         final Frame frame = metadata.getTrajReferenceFrame().asFrame();
  87.         if (frame == null) {
  88.             throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME,
  89.                                       metadata.getTrajReferenceFrame().getName());
  90.         }
  91.         return frame;
  92.     }

  93.     /** {@inheritDoc} */
  94.     @Override
  95.     public int getInterpolationSamples() {
  96.         return metadata.getInterpolationDegree() + 1;
  97.     }

  98.     /** {@inheritDoc} */
  99.     @Override
  100.     public CartesianDerivativesFilter getAvailableDerivatives() {
  101.         return states.get(0).getAvailableDerivatives();
  102.     }

  103.     /** {@inheritDoc} */
  104.     @Override
  105.     public AbsoluteDate getStart() {
  106.         return states.get(0).getDate();
  107.     }

  108.     /** {@inheritDoc} */
  109.     @Override
  110.     public AbsoluteDate getStop() {
  111.         return states.get(states.size() - 1).getDate();
  112.     }

  113.     /** {@inheritDoc} */
  114.     @Override
  115.     public List<TimeStampedPVCoordinates> getCoordinates() {
  116.         return states.stream().map(os -> os.toCartesian(body, mu)).collect(Collectors.toList());
  117.     }

  118. }