ModifiedFrame.java

  1. /* Contributed in the public domain.
  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.definitions;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.bodies.CelestialBody;
  20. import org.orekit.frames.FieldTransform;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.frames.Transform;
  23. import org.orekit.frames.TransformProvider;
  24. import org.orekit.time.AbsoluteDate;
  25. import org.orekit.time.FieldAbsoluteDate;

  26. /**
  27.  * A reference frame created from the {@code REF_FRAME} and {@code CENTER_NAME} is a CCSDS
  28.  * OPM, OMM, or OEM file.
  29.  *
  30.  * @author Evan Ward
  31.  */
  32. public class ModifiedFrame extends Frame {

  33.     /** Reference frame used to create this frame. */
  34.     private final CelestialBodyFrame refFrame;

  35.     /** Value of the CENTER_NAME keyword in the ODM file used to create this frame. */
  36.     private final String centerName;

  37.     /**
  38.      * Create a CCSDS reference frame by changing the origin of an existing frame.
  39.      *
  40.      * @param frame      the existing frame that specifies the orientation.
  41.      * @param refFrame   the reference frame used to create this frame.
  42.      * @param body       the new origin.
  43.      * @param centerName the value of the {@code CENTER_NAME} key word used to create
  44.      *                   {@code body}.
  45.      */
  46.     public ModifiedFrame(final Frame frame,
  47.                          final CelestialBodyFrame refFrame,
  48.                          final CelestialBody body,
  49.                          final String centerName) {
  50.         super(frame, new OriginTransformProvider(body, frame),
  51.               body.getName() + "/" + frame.getName(), frame.isPseudoInertial());
  52.         this.refFrame   = refFrame;
  53.         this.centerName = centerName;
  54.     }

  55.     /**
  56.      * Get the CCSDS reference frame.
  57.      *
  58.      * @return the reference frame used to create this frame.
  59.      */
  60.     public CelestialBodyFrame getRefFrame() {
  61.         return refFrame;
  62.     }

  63.     /**
  64.      * Get the CCSDS center name.
  65.      *
  66.      * @return the value of the {@code CENTER_NAME} key word used to specify the origin of
  67.      * this frame.
  68.      */
  69.     public String getCenterName() {
  70.         return centerName;
  71.     }

  72.     /** Transform provider for {@link ModifiedFrame}. */
  73.     private static class OriginTransformProvider implements TransformProvider {

  74.         /** The new origin. */
  75.         private final CelestialBody body;

  76.         /** The original frame, specifying the orientation. */
  77.         private final Frame frame;

  78.         /**
  79.          * Create a transform provider to change the origin of an existing frame.
  80.          *
  81.          * @param frame the existing frame that specifies the orientation.
  82.          * @param body  the new origin.
  83.          */
  84.         OriginTransformProvider(final CelestialBody body, final Frame frame) {
  85.             this.body = body;
  86.             this.frame = frame;
  87.         }

  88.         @Override
  89.         public Transform getTransform(final AbsoluteDate date) {
  90.             return new Transform(date, body.getPVCoordinates(date, frame).negate());
  91.         }

  92.         @Override
  93.         public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(
  94.                 final FieldAbsoluteDate<T> date) {
  95.             return new FieldTransform<>(
  96.                     date,
  97.                     body.getPVCoordinates(date, frame).negate());
  98.         }

  99.     }

  100. }