FieldInertia.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.CalculusFieldElement;
  19. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;

  20. /** Container for inertia of a 3D object.
  21.  * <p>
  22.  * Instances of this class are immutable
  23.  * </p>
  24.  * @param <T> type of the field elements
  25.  * @author Luc Maisonobe
  26.  * @since 12.0
  27.  */
  28. public class FieldInertia<T extends CalculusFieldElement<T>> {

  29.     /** Inertia along first axis. */
  30.     private final FieldInertiaAxis<T> iA1;

  31.     /** Inertia along second axis. */
  32.     private final FieldInertiaAxis<T> iA2;

  33.     /** Inertia along third axis. */
  34.     private final FieldInertiaAxis<T> iA3;

  35.     /** Simple constructor from principal axes.
  36.      * @param iA1 inertia along first axis
  37.      * @param iA2 inertia along second axis
  38.      * @param iA3 inertia along third axis
  39.      */
  40.     FieldInertia(final FieldInertiaAxis<T> iA1, final FieldInertiaAxis<T> iA2, final FieldInertiaAxis<T> iA3) {
  41.         this.iA1 = iA1;
  42.         this.iA2 = iA2;
  43.         this.iA3 = iA3;
  44.     }

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

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

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

  72.     /** Get inertia along first axis.
  73.      * @return inertia along first axis
  74.      */
  75.     public FieldInertiaAxis<T> getInertiaAxis1() {
  76.         return iA1;
  77.     }

  78.     /** Get inertia along second axis.
  79.      * @return inertia along second axis
  80.      */
  81.     public FieldInertiaAxis<T> getInertiaAxis2() {
  82.         return iA2;
  83.     }

  84.     /** Get inertia along third axis.
  85.      * @return inertia along third axis
  86.      */
  87.     public FieldInertiaAxis<T> getInertiaAxis3() {
  88.         return iA3;
  89.     }

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

  102. }