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  package org.orekit.attitudes;
18  
19  
20  import org.hipparchus.CalculusFieldElement;
21  import org.hipparchus.geometry.euclidean.threed.FieldRotation;
22  import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
23  import org.hipparchus.geometry.euclidean.threed.Rotation;
24  import org.hipparchus.geometry.euclidean.threed.Vector3D;
25  import org.orekit.frames.Frame;
26  import org.orekit.time.AbsoluteDate;
27  import org.orekit.time.FieldAbsoluteDate;
28  import org.orekit.utils.AngularCoordinates;
29  import org.orekit.utils.FieldAngularCoordinates;
30  import org.orekit.utils.FieldPVCoordinatesProvider;
31  import org.orekit.utils.PVCoordinatesProvider;
32  
33  /** This interface represents an attitude provider that modifies/wraps another underlying provider.
34   * @author Luc Maisonobe
35   * @since 5.1
36   */
37  public interface AttitudeProviderModifier extends AttitudeProvider {
38  
39      /** Get the underlying attitude provider.
40       * @return underlying attitude provider
41       */
42      AttitudeProvider getUnderlyingAttitudeProvider();
43  
44      /**
45       * Wrap the input provider with a new one always returning attitudes with zero rotation rate and acceleration.
46       * It is not physically sound, but remains useful for performance when a full, physical attitude with time derivatives is not needed.
47       * @param attitudeProvider provider to wrap
48       * @return wrapping provider
49       * @since 12.1
50       */
51      static AttitudeProviderModifier getFrozenAttitudeProvider(final AttitudeProvider attitudeProvider) {
52          return new AttitudeProviderModifier() {
53              @Override
54              public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
55                  final Rotation rotation = attitudeProvider.getAttitudeRotation(pvProv, date, frame);
56                  final AngularCoordinates angularCoordinates = new AngularCoordinates(rotation, Vector3D.ZERO);
57                  return new Attitude(date, frame, angularCoordinates);
58              }
59  
60              @Override
61              public <T extends CalculusFieldElement<T>> FieldAttitude<T> getAttitude(final FieldPVCoordinatesProvider<T> pvProv, final FieldAbsoluteDate<T> date, final Frame frame) {
62                  final FieldRotation<T> rotation = attitudeProvider.getAttitudeRotation(pvProv, date, frame);
63                  final FieldAngularCoordinates<T> angularCoordinates = new FieldAngularCoordinates<>(rotation, FieldVector3D.getZero(date.getField()));
64                  return new FieldAttitude<>(date, frame, angularCoordinates);
65              }
66  
67              @Override
68              public AttitudeProvider getUnderlyingAttitudeProvider() {
69                  return attitudeProvider;
70              }
71          };
72      }
73  }