BodyCenterPointing.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.RealFieldElement;
  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.errors.OrekitException;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.time.FieldAbsoluteDate;
  28. import org.orekit.utils.FieldPVCoordinatesProvider;
  29. import org.orekit.utils.PVCoordinatesProvider;
  30. import org.orekit.utils.TimeStampedFieldPVCoordinates;
  31. import org.orekit.utils.TimeStampedPVCoordinates;

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

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

  44.     /** Serializable UID. */
  45.     private static final long serialVersionUID = 20150529L;

  46.     /** Body ellipsoid.  */
  47.     private final Ellipsoid ellipsoid;

  48.     /** Creates new instance.
  49.      * @param inertialFrame frame in which orbital velocities are computed
  50.      * @param shape Body shape
  51.      * @exception OrekitException if the frame specified is not a pseudo-inertial frame
  52.      * @since 7.1
  53.      */
  54.     public BodyCenterPointing(final Frame inertialFrame, final Ellipsoid shape)
  55.         throws OrekitException {
  56.         super(inertialFrame, shape.getFrame());
  57.         this.ellipsoid = shape;
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public TimeStampedPVCoordinates getTargetPV(final PVCoordinatesProvider pvProv,
  62.                                                 final AbsoluteDate date, final Frame frame)
  63.         throws OrekitException {

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

  66.         // central projection to ground (NOT the classical nadir point)
  67.         final double u     = scInBodyFrame.getPosition().getX() / ellipsoid.getA();
  68.         final double v     = scInBodyFrame.getPosition().getY() / ellipsoid.getB();
  69.         final double w     = scInBodyFrame.getPosition().getZ() / ellipsoid.getC();
  70.         final double d2    = u * u + v * v + w * w;
  71.         final double d     = FastMath.sqrt(d2);
  72.         final double ratio = 1.0 / d;
  73.         final Vector3D projectedP = new Vector3D(ratio, scInBodyFrame.getPosition());

  74.         // velocity
  75.         final double uDot     = scInBodyFrame.getVelocity().getX() / ellipsoid.getA();
  76.         final double vDot     = scInBodyFrame.getVelocity().getY() / ellipsoid.getB();
  77.         final double wDot     = scInBodyFrame.getVelocity().getZ() / ellipsoid.getC();
  78.         final double dDot     = MathArrays.linearCombination(u, uDot, v, vDot, w, wDot) / d;
  79.         final double ratioDot = -dDot / d2;
  80.         final Vector3D projectedV = new Vector3D(ratio,    scInBodyFrame.getVelocity(),
  81.                                                  ratioDot, scInBodyFrame.getPosition());

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

  92.         final TimeStampedPVCoordinates projected =
  93.                 new TimeStampedPVCoordinates(date, projectedP, projectedV, projectedA);
  94.         return getBodyFrame().getTransformTo(frame, date).transformPVCoordinates(projected);

  95.     }

  96.     /** {@inheritDoc} */
  97.     public <T extends RealFieldElement<T>> TimeStampedFieldPVCoordinates<T> getTargetPV(final FieldPVCoordinatesProvider<T> pvProv,
  98.                                                                                         final FieldAbsoluteDate<T> date, final Frame frame)
  99.         throws OrekitException {

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

  102.         // central projection to ground (NOT the classical nadir point)
  103.         final T u     = scInBodyFrame.getPosition().getX().divide(ellipsoid.getA());
  104.         final T v     = scInBodyFrame.getPosition().getY().divide(ellipsoid.getB());
  105.         final T w     = scInBodyFrame.getPosition().getZ().divide(ellipsoid.getC());
  106.         final T d2    = u.pow(2).add(v.pow(2)).add(w.pow(2));
  107.         final T d     = d2.sqrt();
  108.         final T ratio = d.reciprocal();
  109.         final FieldVector3D<T> projectedP = new FieldVector3D<>(ratio, scInBodyFrame.getPosition());

  110.         // velocity
  111.         final T uDot     = scInBodyFrame.getVelocity().getX().divide(ellipsoid.getA());
  112.         final T vDot     = scInBodyFrame.getVelocity().getY().divide(ellipsoid.getB());
  113.         final T wDot     = scInBodyFrame.getVelocity().getZ().divide(ellipsoid.getC());
  114.         //we aren't using the linearCombination in the library
  115.         final T dDot     = (u.multiply(uDot).add(v.multiply(vDot)).add(w.multiply(wDot))).divide(d);
  116.         final T ratioDot = dDot.multiply(-1).divide(d2);
  117.         final FieldVector3D<T> projectedV = new FieldVector3D<>(ratio,    scInBodyFrame.getVelocity(),
  118.                                                                 ratioDot, scInBodyFrame.getPosition());

  119.         // acceleration
  120.         final T uDotDot      = scInBodyFrame.getAcceleration().getX().divide(ellipsoid.getA());
  121.         final T vDotDot      = scInBodyFrame.getAcceleration().getY().divide(ellipsoid.getB());
  122.         final T wDotDot      = scInBodyFrame.getAcceleration().getZ().divide(ellipsoid.getC());
  123.         final T dDotDot      = u.multiply(uDotDot).add(v.multiply(vDotDot)).add(w.multiply( wDotDot)
  124.                                          .add(uDot.pow(2).add(vDot.pow(2)).add(wDot.pow(2)).subtract(dDot.pow(2))))
  125.                                          .divide(d);
  126.         final T ratioDotDot  = (dDot.pow(2).multiply(2).subtract(d.multiply(dDotDot))).divide(d.multiply(d2));
  127.         final FieldVector3D<T> projectedA = new FieldVector3D<>(ratio,                scInBodyFrame.getAcceleration(),
  128.                                                                 ratioDot.multiply(2), scInBodyFrame.getVelocity(),
  129.                                                                 ratioDotDot,          scInBodyFrame.getPosition());
  130.         final TimeStampedFieldPVCoordinates<T> projected =
  131.                 new TimeStampedFieldPVCoordinates<>(date, projectedP, projectedV, projectedA);
  132.         return getBodyFrame().getTransformTo(frame, date.toAbsoluteDate()).transformPVCoordinates(projected);

  133.     }

  134. }