AlongTrackAiming.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.models.earth.tessellation;

  18. import java.util.List;

  19. import org.hipparchus.analysis.differentiation.DSFactory;
  20. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  21. import org.hipparchus.analysis.interpolation.HermiteInterpolator;
  22. import org.hipparchus.geometry.euclidean.threed.Rotation;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.hipparchus.util.FastMath;
  25. import org.hipparchus.util.Pair;
  26. import org.orekit.bodies.GeodeticPoint;
  27. import org.orekit.bodies.OneAxisEllipsoid;
  28. import org.orekit.errors.OrekitException;
  29. import org.orekit.errors.OrekitMessages;
  30. import org.orekit.orbits.Orbit;
  31. import org.orekit.propagation.Propagator;
  32. import org.orekit.propagation.analytical.KeplerianPropagator;
  33. import org.orekit.propagation.events.LatitudeExtremumDetector;
  34. import org.orekit.utils.TimeStampedPVCoordinates;

  35. /** Class used to orient tiles along an orbit track.
  36.  * @see ConstantAzimuthAiming
  37.  * @author Luc Maisonobe
  38.  */
  39. public class AlongTrackAiming implements TileAiming {

  40.     /** Number of sampling steps for the half-track. */
  41.     private static final int SAMPLING_STEPS = 1000;

  42.     /** Ground track over one half orbit. */
  43.     private final List<Pair<GeodeticPoint, TimeStampedPVCoordinates>> halfTrack;

  44.     /** Factory for the DerivativeStructure instances. */
  45.     private final DSFactory factory;

  46.     /** Simple constructor.
  47.      * @param ellipsoid ellipsoid body on which the zone is defined
  48.      * @param orbit orbit along which tiles should be aligned
  49.      * @param isAscending indicator for zone tiling with respect to ascending
  50.      * or descending orbits
  51.      * @exception OrekitException if some frame conversion fails
  52.      */
  53.     public AlongTrackAiming(final OneAxisEllipsoid ellipsoid, final Orbit orbit, final boolean isAscending)
  54.         throws OrekitException {
  55.         this.halfTrack = findHalfTrack(orbit, ellipsoid, isAscending);
  56.         this.factory   = new DSFactory(1, 1);
  57.     }

  58.     /** {@inheritDoc} */
  59.     @Override
  60.     public Vector3D alongTileDirection(final Vector3D point, final GeodeticPoint gp)
  61.         throws OrekitException {

  62.         final double lStart = halfTrack.get(0).getFirst().getLatitude();
  63.         final double lEnd   = halfTrack.get(halfTrack.size() - 1).getFirst().getLatitude();
  64.         // check the point can be reached
  65.         if (gp.getLatitude() < FastMath.min(lStart, lEnd) || gp.getLatitude() > FastMath.max(lStart, lEnd)) {
  66.             throw new OrekitException(OrekitMessages.OUT_OF_RANGE_LATITUDE,
  67.                                       FastMath.toDegrees(gp.getLatitude()),
  68.                                       FastMath.toDegrees(FastMath.min(lStart, lEnd)),
  69.                                       FastMath.toDegrees(FastMath.max(lStart, lEnd)));
  70.         }

  71.         // bracket the point in the half track sample
  72.         int    iInf = 0;
  73.         int    iSup = halfTrack.size() - 1;
  74.         while (iSup - iInf > 1) {
  75.             final int iMiddle = (iSup + iInf) / 2;
  76.             if ((lStart < lEnd) ^ (halfTrack.get(iMiddle).getFirst().getLatitude() > gp.getLatitude())) {
  77.                 // the specified latitude is in the second half
  78.                 iInf = iMiddle;
  79.             } else {
  80.                 // the specified latitude is in the first half
  81.                 iSup = iMiddle;
  82.             }
  83.         }

  84.         // ensure we can get points at iStart, iStart + 1, iStart + 2 and iStart + 3
  85.         final int iStart = FastMath.max(0, FastMath.min(iInf - 1, halfTrack.size() - 4));

  86.         // interpolate ground sliding point at specified latitude
  87.         final HermiteInterpolator interpolator = new HermiteInterpolator();
  88.         for (int i = iStart; i < iStart + 4; ++i) {
  89.             final Vector3D position = halfTrack.get(i).getSecond().getPosition();
  90.             final Vector3D velocity = halfTrack.get(i).getSecond().getVelocity();
  91.             interpolator.addSamplePoint(halfTrack.get(i).getFirst().getLatitude(),
  92.                                         new double[] {
  93.                                             position.getX(), position.getY(), position.getZ(),
  94.                                             velocity.getX(), velocity.getY(), velocity.getZ()
  95.                                         });
  96.         }
  97.         final DerivativeStructure[] p  = interpolator.value(factory.variable(0, gp.getLatitude()));

  98.         // extract interpolated ground position/velocity
  99.         final Vector3D position = new Vector3D(p[0].getValue(),
  100.                                                p[1].getValue(),
  101.                                                p[2].getValue());
  102.         final Vector3D velocity = new Vector3D(p[3].getValue(),
  103.                                                p[4].getValue(),
  104.                                                p[5].getValue());

  105.         // adjust longitude to match the specified one
  106.         final Rotation rotation      = new Rotation(Vector3D.PLUS_K, position, Vector3D.PLUS_K, point);
  107.         final Vector3D fixedVelocity = rotation.applyTo(velocity);

  108.         // the tile direction is aligned with sliding point velocity
  109.         return fixedVelocity.normalize();

  110.     }

  111.     /** Find the ascending or descending part of an orbit track.
  112.      * @param orbit orbit along which tiles should be aligned
  113.      * @param ellipsoid ellipsoid over which track is sampled
  114.      * @param isAscending indicator for zone tiling with respect to ascending
  115.      * or descending orbits
  116.      * @return time stamped ground points on the selected half track
  117.      * @exception OrekitException if some frame conversion fails
  118.      */
  119.     private static List<Pair<GeodeticPoint, TimeStampedPVCoordinates>> findHalfTrack(final Orbit orbit,
  120.                                                                                      final OneAxisEllipsoid ellipsoid,
  121.                                                                                      final boolean isAscending)
  122.         throws OrekitException {

  123.         // find the span of the next half track
  124.         final Propagator propagator = new KeplerianPropagator(orbit);
  125.         final HalfTrackSpanHandler handler = new HalfTrackSpanHandler(isAscending);
  126.         final LatitudeExtremumDetector detector =
  127.                         new LatitudeExtremumDetector(0.25 * orbit.getKeplerianPeriod(), 1.0e-3, ellipsoid).
  128.                         withHandler(handler).
  129.                         withMaxIter(100);
  130.         propagator.addEventDetector(detector);
  131.         propagator.propagate(orbit.getDate().shiftedBy(3 * orbit.getKeplerianPeriod()));

  132.         // sample the half track
  133.         propagator.clearEventsDetectors();
  134.         final HalfTrackSampler sampler = new HalfTrackSampler(ellipsoid);
  135.         propagator.setMasterMode(handler.getEnd().durationFrom(handler.getStart()) / SAMPLING_STEPS, sampler);
  136.         propagator.propagate(handler.getStart(), handler.getEnd());

  137.         return sampler.getHalfTrack();

  138.     }

  139. }