FixedFrameBuilder.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.attitudes;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.frames.FieldTransform;
  20. import org.orekit.frames.Frame;
  21. import org.orekit.frames.Transform;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.FieldAbsoluteDate;
  24. import org.orekit.utils.FieldPVCoordinatesProvider;
  25. import org.orekit.utils.PVCoordinatesProvider;
  26. import org.orekit.utils.TimeStampedAngularCoordinates;
  27. import org.orekit.utils.TimeStampedFieldAngularCoordinates;


  28. /** Builder that assumes angular coordinates are given in a fixed frame.
  29.  * @author Luc Maisonobe
  30.  * @since 11.0
  31.  */
  32. public class FixedFrameBuilder implements AttitudeBuilder {

  33.     /** Reference frame for raw attitudes. */
  34.     private final Frame referenceFrame;

  35.     /** Creates new instance.
  36.      * @param referenceFrame reference frame for raw attitudes
  37.      */
  38.     public FixedFrameBuilder(final Frame referenceFrame) {
  39.         this.referenceFrame = referenceFrame;
  40.     }

  41.     /** {@inheritDoc} */
  42.     @Override
  43.     public Attitude build(final Frame frame, final PVCoordinatesProvider pvProv,
  44.                           final TimeStampedAngularCoordinates rawAttitude) {

  45.         final AbsoluteDate date = rawAttitude.getDate();
  46.         final Transform    t    = frame.getTransformTo(referenceFrame, date);
  47.         final TimeStampedAngularCoordinates frame2Ref =
  48.                         new TimeStampedAngularCoordinates(date,
  49.                                                           t.getRotation(),
  50.                                                           t.getRotationRate(),
  51.                                                           t.getRotationAcceleration());

  52.         return new Attitude(frame, rawAttitude.addOffset(frame2Ref));

  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public <T extends CalculusFieldElement<T>> FieldAttitude<T>
  57.         build(final Frame frame, final FieldPVCoordinatesProvider<T> pvProv,
  58.               final TimeStampedFieldAngularCoordinates<T> rawAttitude) {

  59.         final FieldAbsoluteDate<T> date = rawAttitude.getDate();
  60.         final FieldTransform<T>    t    = frame.getTransformTo(referenceFrame, date);
  61.         final TimeStampedFieldAngularCoordinates<T> frame2Ref =
  62.                         new TimeStampedFieldAngularCoordinates<>(date,
  63.                                                                  t.getRotation(),
  64.                                                                  t.getRotationRate(),
  65.                                                                  t.getRotationAcceleration());

  66.         return new FieldAttitude<>(frame, rawAttitude.addOffset(frame2Ref));

  67.     }

  68. }