LofOffsetPointing.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.Line;
  19. import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
  20. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  21. import org.orekit.bodies.BodyShape;
  22. import org.orekit.bodies.GeodeticPoint;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.frames.Frame;
  26. import org.orekit.frames.Transform;
  27. import org.orekit.time.AbsoluteDate;
  28. import org.orekit.utils.Constants;
  29. import org.orekit.utils.PVCoordinates;
  30. import org.orekit.utils.PVCoordinatesProvider;


  31. /**
  32.  * This class provides a default attitude provider.

  33.  * <p>
  34.  * The attitude pointing law is defined by an attitude provider and
  35.  * the satellite axis vector chosen for pointing.
  36.  * <p>
  37.  * @author V&eacute;ronique Pommier-Maurussane
  38.  */
  39. public class LofOffsetPointing extends GroundPointing {

  40.     /** Serializable UID. */
  41.     private static final long serialVersionUID = -713570668596014285L;

  42.     /** Rotation from local orbital frame. */
  43.     private final AttitudeProvider attitudeLaw;

  44.     /** Body shape. */
  45.     private final BodyShape shape;

  46.     /** Chosen satellite axis for pointing, given in satellite frame. */
  47.     private final Vector3D satPointingVector;

  48.     /** Creates new instance.
  49.      * @param shape Body shape
  50.      * @param attLaw Attitude law
  51.      * @param satPointingVector satellite vector defining the pointing direction
  52.      */
  53.     public LofOffsetPointing(final BodyShape shape, final AttitudeProvider attLaw,
  54.                              final Vector3D satPointingVector) {
  55.         super(shape.getBodyFrame());
  56.         this.shape = shape;
  57.         this.attitudeLaw = attLaw;
  58.         this.satPointingVector = satPointingVector;
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public Attitude getAttitude(final PVCoordinatesProvider pvProv,
  63.                                 final AbsoluteDate date, final Frame frame)
  64.         throws OrekitException {
  65.         return attitudeLaw.getAttitude(pvProv, date, frame);
  66.     }

  67.     /** {@inheritDoc} */
  68.     protected Vector3D getTargetPoint(final PVCoordinatesProvider pvProv,
  69.                                       final AbsoluteDate date, final Frame frame)
  70.         throws OrekitException {

  71.         final PVCoordinates pv = pvProv.getPVCoordinates(date, frame);

  72.         // Compute satellite state at given date in orbit frame
  73.         final Rotation satRot = attitudeLaw.getAttitude(pvProv, date, frame).getRotation();

  74.         // Compute satellite pointing axis and position/velocity in body frame
  75.         final Transform t = frame.getTransformTo(shape.getBodyFrame(), date);
  76.         final Vector3D pointingBodyFrame =
  77.             t.transformVector(satRot.applyInverseTo(satPointingVector));
  78.         final Vector3D pBodyFrame = t.transformPosition(pv.getPosition());

  79.         // Line from satellite following pointing direction
  80.         // we use arbitrarily the Earth radius as a scaling factor, it could be anything else
  81.         final Line pointingLine = new Line(pBodyFrame,
  82.                                            pBodyFrame.add(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, pointingBodyFrame));

  83.         // Intersection with body shape
  84.         final GeodeticPoint gpIntersection =
  85.             shape.getIntersectionPoint(pointingLine, pBodyFrame, shape.getBodyFrame(), date);
  86.         final Vector3D vIntersection =
  87.             (gpIntersection == null) ? null : shape.transform(gpIntersection);

  88.         // Check there is an intersection and it is not in the reverse pointing direction
  89.         if ((vIntersection == null) ||
  90.             (Vector3D.dotProduct(vIntersection.subtract(pBodyFrame), pointingBodyFrame) < 0)) {
  91.             throw new OrekitException(OrekitMessages.ATTITUDE_POINTING_LAW_DOES_NOT_POINT_TO_GROUND);
  92.         }

  93.         return shape.getBodyFrame().getTransformTo(frame, date).transformPosition(vIntersection);

  94.     }

  95. }