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