Inertia.java

  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. import org.hipparchus.geometry.euclidean.threed.Vector3D;

  19. /** Container for inertia of a 3D object.
  20.  * <p>
  21.  * Instances of this class are immutable
  22.  * </p>
  23.  * @author Luc Maisonobe
  24.  * @since 12.0
  25.  */
  26. public class Inertia {

  27.     /** Inertia along first axis. */
  28.     private final InertiaAxis iA1;

  29.     /** Inertia along second axis. */
  30.     private final InertiaAxis iA2;

  31.     /** Inertia along third axis. */
  32.     private final InertiaAxis iA3;

  33.     /** Simple constructor from principal axes.
  34.      * @param iA1 inertia along first axis
  35.      * @param iA2 inertia along second axis
  36.      * @param iA3 inertia along third axis
  37.      */
  38.     public Inertia(final InertiaAxis iA1, final InertiaAxis iA2, final InertiaAxis iA3) {
  39.         this.iA1 = iA1;
  40.         this.iA2 = iA2;
  41.         this.iA3 = iA3;
  42.     }

  43.     /** Swap axes 1 and 2.
  44.      * <p>
  45.      * The instance is unchanged.
  46.      * </p>
  47.      * @return inertia with swapped axes
  48.      */
  49.     public Inertia swap12() {
  50.         return new Inertia(iA2, iA1, iA3.negate());
  51.     }

  52.     /** Swap axes 1 and 3.
  53.      * <p>
  54.      * The instance is unchanged.
  55.      * </p>
  56.      * @return inertia with swapped axes
  57.      */
  58.     public Inertia swap13() {
  59.         return new Inertia(iA3, iA2.negate(), iA1);
  60.     }

  61.     /** Swap axes 2 and 3.
  62.      * <p>
  63.      * The instance is unchanged.
  64.      * </p>
  65.      * @return inertia with swapped axes
  66.      */
  67.     public Inertia swap23() {
  68.         return new Inertia(iA1.negate(), iA3, iA2);
  69.     }

  70.     /** Get inertia along first axis.
  71.      * @return inertia along first axis
  72.      */
  73.     public InertiaAxis getInertiaAxis1() {
  74.         return iA1;
  75.     }

  76.     /** Get inertia along second axis.
  77.      * @return inertia along second axis
  78.      */
  79.     public InertiaAxis getInertiaAxis2() {
  80.         return iA2;
  81.     }

  82.     /** Get inertia along third axis.
  83.      * @return inertia along third axis
  84.      */
  85.     public InertiaAxis getInertiaAxis3() {
  86.         return iA3;
  87.     }

  88.     /** Compute angular momentum.
  89.      * @param rotationRate rotation rate in body frame.
  90.      * @return angular momentum in body frame
  91.      */
  92.     public Vector3D momentum(final Vector3D rotationRate) {
  93.         final Vector3D a1 = iA1.getA();
  94.         final Vector3D a2 = iA2.getA();
  95.         final Vector3D a3 = iA3.getA();
  96.         return new Vector3D(iA1.getI() * Vector3D.dotProduct(rotationRate, a1), a1,
  97.                             iA2.getI() * Vector3D.dotProduct(rotationRate, a2), a2,
  98.                             iA3.getI() * Vector3D.dotProduct(rotationRate, a3), a3);
  99.     }

  100. }