AlongTrackAiming.java

  1. /* Copyright 2002-2022 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.models.earth.tessellation;

  18. import java.util.Arrays;
  19. import java.util.List;

  20. import org.hipparchus.analysis.differentiation.Gradient;
  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.attitudes.InertialProvider;
  27. import org.orekit.bodies.GeodeticPoint;
  28. import org.orekit.bodies.OneAxisEllipsoid;
  29. import org.orekit.orbits.Orbit;
  30. import org.orekit.propagation.Propagator;
  31. import org.orekit.propagation.analytical.KeplerianPropagator;
  32. import org.orekit.propagation.events.LatitudeExtremumDetector;
  33. import org.orekit.utils.TimeStampedPVCoordinates;

  34. /** Class used to orient tiles along an orbit track.
  35.  * @see ConstantAzimuthAiming
  36.  * @see DivertedSingularityAiming
  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.     /** Indicator for orbit type. */
  45.     private final boolean retrogradeOrbit;

  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.      */
  52.     public AlongTrackAiming(final OneAxisEllipsoid ellipsoid, final Orbit orbit, final boolean isAscending) {
  53.         this.halfTrack       = findHalfTrack(orbit, ellipsoid, isAscending);
  54.         this.retrogradeOrbit = orbit.getPVCoordinates().getMomentum().getZ() < 0;
  55.     }

  56.     /** {@inheritDoc} */
  57.     @Override
  58.     public List<GeodeticPoint> getSingularPoints() {
  59.         return Arrays.asList(GeodeticPoint.NORTH_POLE, GeodeticPoint.SOUTH_POLE);
  60.     }

  61.     /** {@inheritDoc} */
  62.     @Override
  63.     public Vector3D alongTileDirection(final Vector3D point, final GeodeticPoint gp) {

  64.         final double lStart = halfTrack.get(0).getFirst().getLatitude();
  65.         final double lEnd   = halfTrack.get(halfTrack.size() - 1).getFirst().getLatitude();

  66.         // special handling for out of range latitudes
  67.         if (gp.getLatitude() < FastMath.min(lStart, lEnd) || gp.getLatitude() > FastMath.max(lStart, lEnd)) {
  68.             return retrogradeOrbit ? gp.getWest() : gp.getEast();
  69.         }

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

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

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

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

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

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

  109.     }

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

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

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

  135.         return sampler.getHalfTrack();

  136.     }

  137. }