SpinFinder.java

  1. /* Copyright 2023 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.files.ccsds.ndm.adm;

  18. import org.hipparchus.geometry.euclidean.threed.Rotation;
  19. import org.hipparchus.geometry.euclidean.threed.RotationConvention;
  20. import org.hipparchus.geometry.euclidean.threed.RotationOrder;
  21. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  22. import org.hipparchus.util.FastMath;
  23. import org.hipparchus.util.MathUtils;
  24. import org.orekit.attitudes.Attitude;
  25. import org.orekit.utils.TimeStampedAngularCoordinates;

  26. /** Utility to extract spin data.
  27.  * <p>
  28.  * In CCSDS ADM, spin axis is forced to Z. It is not the instantaneous rotation
  29.  * rate as it also moves.
  30.  * </p>
  31.  * @author Luc Maisonobe
  32.  * @since 12.0
  33.  */
  34. class SpinFinder {

  35.     /** Spin axis. */
  36.     private final Vector3D spin;

  37.     /** Right ascension of spin axis (rad). */
  38.     private final double spinAlpha;

  39.     /** declination of spin axis (rad). */
  40.     private final double spinDelta;

  41.     /** Spin angle. */
  42.     private final double spinAngle;

  43.     /** Build from attitude rotation.
  44.      * @param attitude angular coordinates, using {@link Attitude Attitude} convention
  45.      * (i.e. from inertial frame to spacecraft frame)
  46.      */
  47.     SpinFinder(final TimeStampedAngularCoordinates attitude) {
  48.         // spin axis is forced to Z (but it is not the instantaneous rotation rate as it also moves)
  49.         spin      = attitude.getRotation().applyInverseTo(Vector3D.PLUS_K);
  50.         spinAlpha = spin.getAlpha();
  51.         spinDelta = spin.getDelta();
  52.         final Rotation alignSpin   = new Rotation(RotationOrder.ZXZ, RotationConvention.FRAME_TRANSFORM,
  53.                                                   MathUtils.SEMI_PI + spinAlpha,
  54.                                                   MathUtils.SEMI_PI - spinDelta,
  55.                                                   0.0);
  56.         final Rotation phasing     = attitude.getRotation().applyTo(alignSpin.revert());
  57.         spinAngle = FastMath.copySign(phasing.getAngle(),
  58.                                       phasing.getAxis(RotationConvention.FRAME_TRANSFORM).getZ());

  59.     }

  60.     /** Get the spin axis in inertial frame.
  61.      * @return spin axis in inertial frame
  62.      */
  63.     public Vector3D getSpin() {
  64.         return spin;
  65.     }

  66.     /** Get the declination of spin axis.
  67.      * @return declination of spin axis (rad)
  68.      */
  69.     public double getSpinDelta() {
  70.         return spinDelta;
  71.     }

  72.     /** Get the right ascension of spin axis.
  73.      * @return right ascension of spin axis (rad)
  74.      */
  75.     public double getSpinAlpha() {
  76.         return spinAlpha;
  77.     }

  78.     /** Get the spin angle.
  79.      * @return spin angle (rad)
  80.      */
  81.     public double getSpinAngle() {
  82.         return spinAngle;
  83.     }

  84. }