BodyCenterPointing.java

  1. /* Copyright 2002-2025 CS GROUP
  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. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  21. import org.hipparchus.util.FastMath;
  22. import org.hipparchus.util.MathArrays;
  23. import org.orekit.bodies.Ellipsoid;
  24. import org.orekit.frames.Frame;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.time.FieldAbsoluteDate;
  27. import org.orekit.utils.FieldPVCoordinatesProvider;
  28. import org.orekit.utils.PVCoordinatesProvider;
  29. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  30. import org.orekit.utils.TimeStampedPVCoordinates;

  31. /**
  32.  * This class handles body center pointing attitude provider.

  33.  * <p>
  34.  * This class represents the attitude provider where the satellite z axis is
  35.  * pointing to the body frame center.</p>
  36.  * <p>
  37.  * The object <code>BodyCenterPointing</code> is guaranteed to be immutable.
  38.  * </p>
  39.  * @see     GroundPointing
  40.  * @author V&eacute;ronique Pommier-Maurussane
  41.  */
  42. public class BodyCenterPointing extends GroundPointing {

  43.     /** Body ellipsoid.  */
  44.     private final Ellipsoid ellipsoid;

  45.     /** Creates new instance.
  46.      * @param inertialFrame frame in which orbital velocities are computed
  47.      * @param shape Body shape
  48.      * @since 7.1
  49.      */
  50.     public BodyCenterPointing(final Frame inertialFrame, final Ellipsoid shape) {
  51.         super(inertialFrame, shape.getFrame());
  52.         this.ellipsoid = shape;
  53.     }

  54.     /** {@inheritDoc} */
  55.     @Override
  56.     public TimeStampedPVCoordinates getTargetPV(final PVCoordinatesProvider pvProv,
  57.                                                 final AbsoluteDate date, final Frame frame) {

  58.         // spacecraft coordinates in body frame
  59.         final TimeStampedPVCoordinates scInBodyFrame = pvProv.getPVCoordinates(date, getBodyFrame());

  60.         // central projection to ground (NOT the classical nadir point)
  61.         final double u     = scInBodyFrame.getPosition().getX() / ellipsoid.getA();
  62.         final double v     = scInBodyFrame.getPosition().getY() / ellipsoid.getB();
  63.         final double w     = scInBodyFrame.getPosition().getZ() / ellipsoid.getC();
  64.         final double d2    = u * u + v * v + w * w;
  65.         final double d     = FastMath.sqrt(d2);
  66.         final double ratio = 1.0 / d;
  67.         final Vector3D projectedP = new Vector3D(ratio, scInBodyFrame.getPosition());

  68.         // velocity
  69.         final double uDot     = scInBodyFrame.getVelocity().getX() / ellipsoid.getA();
  70.         final double vDot     = scInBodyFrame.getVelocity().getY() / ellipsoid.getB();
  71.         final double wDot     = scInBodyFrame.getVelocity().getZ() / ellipsoid.getC();
  72.         final double dDot     = MathArrays.linearCombination(u, uDot, v, vDot, w, wDot) / d;
  73.         final double ratioDot = -dDot / d2;
  74.         final Vector3D projectedV = new Vector3D(ratio,    scInBodyFrame.getVelocity(),
  75.                                                  ratioDot, scInBodyFrame.getPosition());

  76.         // acceleration
  77.         final double uDotDot      = scInBodyFrame.getAcceleration().getX() / ellipsoid.getA();
  78.         final double vDotDot      = scInBodyFrame.getAcceleration().getY() / ellipsoid.getB();
  79.         final double wDotDot      = scInBodyFrame.getAcceleration().getZ() / ellipsoid.getC();
  80.         final double dDotDot      = (MathArrays.linearCombination(u, uDotDot, v, vDotDot, w, wDotDot) +
  81.                                      uDot * uDot + vDot * vDot + wDot * wDot - dDot * dDot) / d;
  82.         final double ratioDotDot  = (2 * dDot * dDot - d * dDotDot) / (d * d2);
  83.         final Vector3D projectedA = new Vector3D(ratio,        scInBodyFrame.getAcceleration(),
  84.                                                  2 * ratioDot, scInBodyFrame.getVelocity(),
  85.                                                  ratioDotDot,  scInBodyFrame.getPosition());

  86.         final TimeStampedPVCoordinates projected =
  87.                 new TimeStampedPVCoordinates(date, projectedP, projectedV, projectedA);
  88.         return getBodyFrame().getTransformTo(frame, date).transformPVCoordinates(projected);

  89.     }

  90.     /** {@inheritDoc} */
  91.     @Override
  92.     protected Vector3D getTargetPosition(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) {
  93.         // spacecraft coordinates in body frame
  94.         final Vector3D scPositionInBodyFrame = pvProv.getPosition(date, getBodyFrame());

  95.         // central projection to ground (NOT the classical nadir point)
  96.         final double u     = scPositionInBodyFrame.getX() / ellipsoid.getA();
  97.         final double v     = scPositionInBodyFrame.getY() / ellipsoid.getB();
  98.         final double w     = scPositionInBodyFrame.getZ() / ellipsoid.getC();
  99.         final double d2    = u * u + v * v + w * w;
  100.         final double d     = FastMath.sqrt(d2);
  101.         final double ratio = 1.0 / d;
  102.         final Vector3D projectedP = new Vector3D(ratio, scPositionInBodyFrame);

  103.         return getBodyFrame().getStaticTransformTo(frame, date).transformPosition(projectedP);
  104.     }

  105.     /** {@inheritDoc} */
  106.     public <T extends CalculusFieldElement<T>> TimeStampedFieldPVCoordinates<T> getTargetPV(final FieldPVCoordinatesProvider<T> pvProv,
  107.                                                                                             final FieldAbsoluteDate<T> date,
  108.                                                                                             final Frame frame) {

  109.         // spacecraft coordinates in body frame
  110.         final TimeStampedFieldPVCoordinates<T> scInBodyFrame = pvProv.getPVCoordinates(date, getBodyFrame());

  111.         // central projection to ground (NOT the classical nadir point)
  112.         final T u     = scInBodyFrame.getPosition().getX().divide(ellipsoid.getA());
  113.         final T v     = scInBodyFrame.getPosition().getY().divide(ellipsoid.getB());
  114.         final T w     = scInBodyFrame.getPosition().getZ().divide(ellipsoid.getC());
  115.         final T d2    = u.pow(2).add(v.pow(2)).add(w.pow(2));
  116.         final T d     = d2.sqrt();
  117.         final T ratio = d.reciprocal();
  118.         final FieldVector3D<T> projectedP = new FieldVector3D<>(ratio, scInBodyFrame.getPosition());

  119.         // velocity
  120.         final T uDot     = scInBodyFrame.getVelocity().getX().divide(ellipsoid.getA());
  121.         final T vDot     = scInBodyFrame.getVelocity().getY().divide(ellipsoid.getB());
  122.         final T wDot     = scInBodyFrame.getVelocity().getZ().divide(ellipsoid.getC());
  123.         //we aren't using the linearCombination in the library
  124.         final T dDot     = (u.multiply(uDot).add(v.multiply(vDot)).add(w.multiply(wDot))).divide(d);
  125.         final T ratioDot = dDot.multiply(-1).divide(d2);
  126.         final FieldVector3D<T> projectedV = new FieldVector3D<>(ratio,    scInBodyFrame.getVelocity(),
  127.                                                                 ratioDot, scInBodyFrame.getPosition());

  128.         // acceleration
  129.         final T uDotDot      = scInBodyFrame.getAcceleration().getX().divide(ellipsoid.getA());
  130.         final T vDotDot      = scInBodyFrame.getAcceleration().getY().divide(ellipsoid.getB());
  131.         final T wDotDot      = scInBodyFrame.getAcceleration().getZ().divide(ellipsoid.getC());
  132.         final T dDotDot      = u.multiply(uDotDot).add(v.multiply(vDotDot)).add(w.multiply( wDotDot)
  133.                                          .add(uDot.pow(2).add(vDot.pow(2)).add(wDot.pow(2)).subtract(dDot.pow(2))))
  134.                                          .divide(d);
  135.         final T ratioDotDot  = (dDot.pow(2).multiply(2).subtract(d.multiply(dDotDot))).divide(d.multiply(d2));
  136.         final FieldVector3D<T> projectedA = new FieldVector3D<>(ratio,                scInBodyFrame.getAcceleration(),
  137.                                                                 ratioDot.multiply(2), scInBodyFrame.getVelocity(),
  138.                                                                 ratioDotDot,          scInBodyFrame.getPosition());
  139.         final TimeStampedFieldPVCoordinates<T> projected =
  140.                 new TimeStampedFieldPVCoordinates<>(date, projectedP, projectedV, projectedA);
  141.         return getBodyFrame().getTransformTo(frame, date).transformPVCoordinates(projected);

  142.     }

  143.     /** {@inheritDoc} */
  144.     @Override
  145.     protected <T extends CalculusFieldElement<T>> FieldVector3D<T> getTargetPosition(final FieldPVCoordinatesProvider<T> pvProv,
  146.                                                                                      final FieldAbsoluteDate<T> date,
  147.                                                                                      final Frame frame) {
  148.         // spacecraft coordinates in body frame
  149.         final FieldVector3D<T> scPositionInBodyFrame = pvProv.getPosition(date, getBodyFrame());

  150.         // central projection to ground (NOT the classical nadir point)
  151.         final T u     = scPositionInBodyFrame.getX().divide(ellipsoid.getA());
  152.         final T v     = scPositionInBodyFrame.getY().divide(ellipsoid.getB());
  153.         final T w     = scPositionInBodyFrame.getZ().divide(ellipsoid.getC());
  154.         final T d     = new FieldVector3D<>(u, v, w).getNorm();
  155.         final FieldVector3D<T> projectedP = new FieldVector3D<>(d.reciprocal(), scPositionInBodyFrame);

  156.         return getBodyFrame().getStaticTransformTo(frame, date).transformPosition(projectedP);
  157.     }
  158. }