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.attitudes;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.frames.FieldTransform;
21  import org.orekit.frames.Frame;
22  import org.orekit.frames.Transform;
23  import org.orekit.time.AbsoluteDate;
24  import org.orekit.time.FieldAbsoluteDate;
25  import org.orekit.utils.FieldPVCoordinatesProvider;
26  import org.orekit.utils.PVCoordinatesProvider;
27  import org.orekit.utils.TimeStampedAngularCoordinates;
28  import org.orekit.utils.TimeStampedFieldAngularCoordinates;
29  
30  
31  /** Builder that assumes angular coordinates are given in a fixed frame.
32   * @author Luc Maisonobe
33   * @since 11.0
34   */
35  public class FixedFrameBuilder implements AttitudeBuilder {
36  
37      /** Reference frame for raw attitudes. */
38      private final Frame referenceFrame;
39  
40      /** Creates new instance.
41       * @param referenceFrame reference frame for raw attitudes
42       */
43      public FixedFrameBuilder(final Frame referenceFrame) {
44          this.referenceFrame = referenceFrame;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public Attitude build(final Frame frame, final PVCoordinatesProvider pvProv,
50                            final TimeStampedAngularCoordinates rawAttitude) {
51  
52          final AbsoluteDate date = rawAttitude.getDate();
53          final Transform    t    = frame.getTransformTo(referenceFrame, date);
54          final TimeStampedAngularCoordinates frame2Ref =
55                          new TimeStampedAngularCoordinates(date,
56                                                            t.getRotation(),
57                                                            t.getRotationRate(),
58                                                            t.getRotationAcceleration());
59  
60          return new Attitude(frame, rawAttitude.addOffset(frame2Ref));
61  
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public <T extends CalculusFieldElement<T>> FieldAttitude<T>
67          build(final Frame frame, final FieldPVCoordinatesProvider<T> pvProv,
68                final TimeStampedFieldAngularCoordinates<T> rawAttitude) {
69  
70          final FieldAbsoluteDate<T> date = rawAttitude.getDate();
71          final FieldTransform<T>    t    = frame.getTransformTo(referenceFrame, date);
72          final TimeStampedFieldAngularCoordinates<T> frame2Ref =
73                          new TimeStampedFieldAngularCoordinates<>(date,
74                                                                   t.getRotation(),
75                                                                   t.getRotationRate(),
76                                                                   t.getRotationAcceleration());
77  
78          return new FieldAttitude<>(frame, rawAttitude.addOffset(frame2Ref));
79  
80      }
81  
82  }