IodGibbs.java

  1. /* Copyright 2002-2020 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.estimation.iod;

  18. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  19. import org.hipparchus.util.FastMath;
  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.estimation.measurements.PV;
  23. import org.orekit.frames.Frame;
  24. import org.orekit.orbits.KeplerianOrbit;
  25. import org.orekit.time.AbsoluteDate;
  26. import org.orekit.utils.PVCoordinates;

  27. /**
  28.  * Gibbs initial orbit determination.
  29.  * An orbit is determined from three position vectors.
  30.  *
  31.  * Reference:
  32.  *  Vallado, D., Fundamentals of Astrodynamics and Applications
  33.  *
  34.  * @author Joris Olympio
  35.  * @since 8.0
  36.  *
  37.  */
  38. public class IodGibbs {

  39.     /** Threshold for checking coplanr vectors. */
  40.     private static final double COPLANAR_THRESHOLD = FastMath.toRadians(5.);

  41.     /** gravitationnal constant. */
  42.     private final double mu;

  43.     /** Creator.
  44.      *
  45.      * @param mu gravitational constant
  46.      */
  47.     public IodGibbs(final double mu) {
  48.         this.mu = mu;
  49.     }

  50.     /** Give an initial orbit estimation, assuming Keplerian motion.
  51.      * All observations should be from the same location.
  52.      *
  53.      * @param frame measure frame
  54.      * @param pv1 PV measure 1 taken in frame
  55.      * @param pv2 PV measure 2 taken in frame
  56.      * @param pv3 PV measure 3 taken in frame
  57.      * @return an initial orbit estimation
  58.      */
  59.     public KeplerianOrbit estimate(final Frame frame, final PV pv1, final PV pv2, final PV pv3) {

  60.         return estimate(frame,
  61.                         pv1.getPosition(), pv1.getDate(),
  62.                         pv2.getPosition(), pv2.getDate(),
  63.                         pv3.getPosition(), pv3.getDate());
  64.     }

  65.     /** Give an initial orbit estimation, assuming Keplerian motion.
  66.      * All observations should be from the same location.
  67.      *
  68.      * @param frame measure frame
  69.      * @param r1 position 1 measured in frame
  70.      * @param date1 date of measure 1
  71.      * @param r2 position 2 measured in frame
  72.      * @param date2 date of measure 2
  73.      * @param r3 position 3 measured in frame
  74.      * @param date3 date of measure 3
  75.      * @return an initial orbit estimation
  76.      */
  77.     public KeplerianOrbit estimate(final Frame frame,
  78.                                    final Vector3D r1, final AbsoluteDate date1,
  79.                                    final Vector3D r2, final AbsoluteDate date2,
  80.                                    final Vector3D r3, final AbsoluteDate date3) {
  81.         // Checks measures are not at the same date
  82.         if (date1.equals(date2) || date1.equals(date3) || date2.equals(date3)) {
  83.             throw new OrekitException(OrekitMessages.NON_DIFFERENT_DATES_FOR_OBSERVATIONS, date1, date2, date3);
  84.         }

  85.         // Checks measures are in the same plane
  86.         final double num = r1.normalize().dotProduct(r2.normalize().crossProduct(r3.normalize()));
  87.         final double alpha = FastMath.PI / 2.0 - FastMath.acos(num);
  88.         if (FastMath.abs(alpha) > COPLANAR_THRESHOLD) {
  89.             throw new OrekitException(OrekitMessages.NON_COPLANAR_POINTS);
  90.         }

  91.         final Vector3D D = r1.crossProduct(r2).add(r2.crossProduct(r3).add(r3.crossProduct(r1)));

  92.         final Vector3D N = (r2.crossProduct(r3)).scalarMultiply(r1.getNorm())
  93.                 .add((r3.crossProduct(r1)).scalarMultiply(r2.getNorm()))
  94.                 .add((r1.crossProduct(r2)).scalarMultiply(r3.getNorm()));

  95.         final Vector3D B = D.crossProduct(r2);

  96.         final Vector3D S = r1.scalarMultiply(r2.getNorm() - r3.getNorm())
  97.                 .add(r2.scalarMultiply(r3.getNorm() - r1.getNorm())
  98.                      .add(r3.scalarMultiply(r1.getNorm() - r2.getNorm())));

  99.         // middle velocity
  100.         final double vm = FastMath.sqrt(mu / (N.getNorm() * D.getNorm()));
  101.         final Vector3D vlEci = B.scalarMultiply(vm / r2.getNorm()).add(S.scalarMultiply(vm));

  102.         // compile a new middle point with position, velocity
  103.         final PVCoordinates pv = new PVCoordinates(r2, vlEci);
  104.         final AbsoluteDate date = date2;

  105.         // compute the equivalent Keplerian orbit
  106.         final KeplerianOrbit orbit = new KeplerianOrbit(pv, frame, date, mu);

  107.         //define the reverse orbit
  108.         final PVCoordinates pv2 = new PVCoordinates(r2, vlEci.scalarMultiply(-1));
  109.         final KeplerianOrbit orbit2 = new KeplerianOrbit(pv2, frame, date, mu);

  110.         //check which orbit is correct
  111.         final Vector3D estP3 = orbit.shiftedBy(date3.durationFrom(date2)).
  112.                 getPVCoordinates().getPosition();
  113.         final double dist = estP3.subtract(r3).getNorm();
  114.         final Vector3D estP3_2 = orbit2.shiftedBy(date3.durationFrom(date2)).
  115.                 getPVCoordinates().getPosition();
  116.         final double dist2 = estP3_2.subtract(r3).getNorm();

  117.         if (dist <= dist2) {
  118.             return orbit;
  119.         } else {
  120.             return orbit2;
  121.         }
  122.     }
  123. }