CelestialBodyPointed.java

  1. /* Copyright 2002-2013 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.apache.commons.math3.geometry.euclidean.threed.Rotation;
  19. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.frames.Frame;
  22. import org.orekit.frames.Transform;
  23. import org.orekit.time.AbsoluteDate;
  24. import org.orekit.utils.PVCoordinates;
  25. import org.orekit.utils.PVCoordinatesProvider;


  26. /**
  27.  * This class handles a celestial body pointed attitude provider.
  28.  * <p>The celestial body pointed law is defined by two main elements:
  29.  * <ul>
  30.  *   <li>a celestial body towards which some satellite axis is exactly aimed</li>
  31.  *   <li>a phasing reference defining the rotation around the pointing axis</li>
  32.  * </ul>
  33.  * </p>
  34.  * <p>
  35.  * The celestial body implicitly defines two of the three degrees of freedom
  36.  * and the phasing reference defines the remaining degree of freedom. This definition
  37.  * can be represented as first aligning exactly the satellite pointing axis to
  38.  * the current direction of the celestial body, and then to find the rotation
  39.  * around this axis such that the satellite phasing axis is in the half-plane
  40.  * defined by a cut line on the pointing axis and containing the celestial
  41.  * phasing reference.
  42.  * </p>
  43.  * <p>
  44.  * In order for this definition to work, the user must ensure that the phasing
  45.  * reference is <strong>never</strong> aligned with the pointing reference.
  46.  * Since the pointed body moves as the date changes, this should be ensured
  47.  * regardless of the date. A simple way to do this for Sun, Moon or any planet
  48.  * pointing is to choose a phasing reference far from the ecliptic plane. Using
  49.  * <code>Vector3D.PLUS_K</code>, the equatorial pole, is perfect in these cases.
  50.  * </p>
  51.  * <p>Instances of this class are guaranteed to be immutable.</p>
  52.  * @author Luc Maisonobe
  53.  */
  54. public class CelestialBodyPointed implements AttitudeProvider {

  55.     /** Serializable UID. */
  56.     private static final long serialVersionUID = 6222161082155807729L;

  57.     /** Frame in which {@link #phasingCel} is defined. */
  58.     private final Frame celestialFrame;

  59.     /** Celestial body to point at. */
  60.     private final PVCoordinatesProvider pointedBody;

  61.     /** Phasing reference, in celestial frame. */
  62.     private final Vector3D phasingCel;

  63.     /** Satellite axis aiming at the pointed body, in satellite frame. */
  64.     private final Vector3D pointingSat;

  65.     /** Phasing reference, in satellite frame. */
  66.     private final Vector3D phasingSat;

  67.     /** Creates new instance.
  68.      * @param celestialFrame frame in which <code>phasingCel</code> is defined
  69.      * @param pointedBody celestial body to point at
  70.      * @param phasingCel phasing reference, in celestial frame
  71.      * @param pointingSat satellite vector defining the pointing direction
  72.      * @param phasingSat phasing reference, in satellite frame
  73.      */
  74.     public CelestialBodyPointed(final Frame celestialFrame,
  75.                                 final PVCoordinatesProvider pointedBody,
  76.                                 final Vector3D phasingCel,
  77.                                 final Vector3D pointingSat,
  78.                                 final Vector3D phasingSat) {
  79.         this.celestialFrame = celestialFrame;
  80.         this.pointedBody    = pointedBody;
  81.         this.phasingCel     = phasingCel;
  82.         this.pointingSat    = pointingSat;
  83.         this.phasingSat     = phasingSat;
  84.     }

  85.     /** {@inheritDoc} */
  86.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  87.                                 final AbsoluteDate date, final Frame frame)
  88.         throws OrekitException {

  89.         final PVCoordinates satPV = pvProv.getPVCoordinates(date, celestialFrame);

  90.         // compute celestial references at the specified date
  91.         final PVCoordinates bodyPV    = pointedBody.getPVCoordinates(date, celestialFrame);
  92.         final PVCoordinates pointing  = new PVCoordinates(satPV, bodyPV);
  93.         final Vector3D      pointingP = pointing.getPosition();
  94.         final double        r2        = Vector3D.dotProduct(pointingP, pointingP);

  95.         // evaluate instant rotation axis due to sat and body motion only (no phasing yet)
  96.         final Vector3D rotAxisCel =
  97.             new Vector3D(1 / r2, Vector3D.crossProduct(pointingP, pointing.getVelocity()));

  98.         // fix instant rotation to take phasing constraint into account
  99.         // (adding a rotation around pointing axis ensuring the motion of the phasing axis
  100.         //  is constrained in the pointing-phasing plane)
  101.         final Vector3D v1    = Vector3D.crossProduct(rotAxisCel, phasingCel);
  102.         final Vector3D v2    = Vector3D.crossProduct(pointingP,  phasingCel);
  103.         final double   compensation = -Vector3D.dotProduct(v1, v2) / v2.getNormSq();
  104.         final Vector3D phasedRotAxisCel = new Vector3D(1.0, rotAxisCel, compensation, pointingP);

  105.         // compute transform from celestial frame to satellite frame
  106.         final Rotation celToSatRotation =
  107.             new Rotation(pointingP, phasingCel, pointingSat, phasingSat);

  108.         // build transform combining rotation and instant rotation axis
  109.         Transform transform = new Transform(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel));
  110.         if (frame != celestialFrame) {
  111.             // prepend transform from specified frame to celestial frame
  112.             transform = new Transform(date, frame.getTransformTo(celestialFrame, date), transform);
  113.         }

  114.         // build the attitude
  115.         return new Attitude(date, frame, transform.getRotation(), transform.getRotationRate());

  116.     }

  117. }