1   /* Copyright 2022-2025 Luc Maisonobe
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.hipparchus.geometry.euclidean.threed.FieldVector3D;
21  
22  /** Container for inertia of a 3D object.
23   * <p>
24   * Instances of this class are immutable
25   * </p>
26   * @param <T> type of the field elements
27   * @author Luc Maisonobe
28   * @since 12.0
29   */
30  public class FieldInertia<T extends CalculusFieldElement<T>> {
31  
32      /** Inertia along first axis. */
33      private final FieldInertiaAxis<T> iA1;
34  
35      /** Inertia along second axis. */
36      private final FieldInertiaAxis<T> iA2;
37  
38      /** Inertia along third axis. */
39      private final FieldInertiaAxis<T> iA3;
40  
41      /** Simple constructor from principal axes.
42       * @param iA1 inertia along first axis
43       * @param iA2 inertia along second axis
44       * @param iA3 inertia along third axis
45       */
46      FieldInertia(final FieldInertiaAxis<T> iA1, final FieldInertiaAxis<T> iA2, final FieldInertiaAxis<T> iA3) {
47          this.iA1 = iA1;
48          this.iA2 = iA2;
49          this.iA3 = iA3;
50      }
51  
52      /** Swap axes 1 and 2.
53       * <p>
54       * The instance is unchanged.
55       * </p>
56       * @return inertia with swapped axes
57       */
58      public FieldInertia<T> swap12() {
59          return new FieldInertia<>(iA2, iA1, iA3.negate());
60      }
61  
62      /** Swap axes 1 and 3.
63       * <p>
64       * The instance is unchanged.
65       * </p>
66       * @return inertia with swapped axes
67       */
68      public FieldInertia<T> swap13() {
69          return new FieldInertia<>(iA3, iA2.negate(), iA1);
70      }
71  
72      /** Swap axes 2 and 3.
73       * <p>
74       * The instance is unchanged.
75       * </p>
76       * @return inertia with swapped axes
77       */
78      public FieldInertia<T> swap23() {
79          return new FieldInertia<>(iA1.negate(), iA3, iA2);
80      }
81  
82      /** Get inertia along first axis.
83       * @return inertia along first axis
84       */
85      public FieldInertiaAxis<T> getInertiaAxis1() {
86          return iA1;
87      }
88  
89      /** Get inertia along second axis.
90       * @return inertia along second axis
91       */
92      public FieldInertiaAxis<T> getInertiaAxis2() {
93          return iA2;
94      }
95  
96      /** Get inertia along third axis.
97       * @return inertia along third axis
98       */
99      public FieldInertiaAxis<T> getInertiaAxis3() {
100         return iA3;
101     }
102 
103     /** Compute angular momentum.
104      * @param rotationRate rotation rate in body frame.
105      * @return angular momentum in body frame
106      */
107     public FieldVector3D<T> momentum(final FieldVector3D<T> rotationRate) {
108         final FieldVector3D<T> a1 = iA1.getA();
109         final FieldVector3D<T> a2 = iA2.getA();
110         final FieldVector3D<T> a3 = iA3.getA();
111         return new FieldVector3D<>(iA1.getI().multiply(FieldVector3D.dotProduct(rotationRate, a1)), a1,
112                                    iA2.getI().multiply(FieldVector3D.dotProduct(rotationRate, a2)), a2,
113                                    iA3.getI().multiply(FieldVector3D.dotProduct(rotationRate, a3)), a3);
114     }
115 
116 }