IodGooding.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.estimation.iod;

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

  25. /**
  26.  * Gooding angles only initial orbit determination, assuming Keplerian motion.
  27.  * An orbit is determined from three angular observations.
  28.  *
  29.  * Reference:
  30.  *    Gooding, R.H., A New Procedure for Orbit Determination Based on Three Lines of Sight (Angles only),
  31.  *    Technical Report 93004, April 1993
  32.  *
  33.  * @author Joris Olympio
  34.  * @since 8.0
  35.  */
  36. public class IodGooding {

  37.     /** Gravitationnal constant. */
  38.     private final double mu;

  39.     /** Normalizing constant for distances. */
  40.     private double R;

  41.     /** Normalizing constant for velocities. */
  42.     private double V;

  43.     /** Normalizing constant for duration. */
  44.     private double T;

  45.     /** observer position 1. */
  46.     private Vector3D vObserverPosition1;

  47.     /** observer position 2. */
  48.     private Vector3D vObserverPosition2;

  49.     /** observer position 3. */
  50.     private Vector3D vObserverPosition3;

  51.     /** Date of the first observation. * */
  52.     private AbsoluteDate date1;

  53.     /** Radius of point 1 (X-R1). */
  54.     private double R1;
  55.     /** Radius of point 2 (X-R2). */
  56.     private double R2;
  57.     /** Radius of point 3 (X-R3). */
  58.     private double R3;

  59.     /** Range of point 1 (O1-R1). */
  60.     private double rho1;
  61.     /** Range of point 2 (O2-R2). */
  62.     private double rho2;
  63.     /** Range of point 3 (O3-R3). */
  64.     private double rho3;

  65.     /** working variable. */
  66.     private double D1;

  67.     /** working variable. */
  68.     private double D3;

  69.     /** factor for FD. */
  70.     private double facFiniteDiff;

  71.     /** Simple Lambert's problem solver. */
  72.     private IodLambert lambert;

  73.     /** Creator.
  74.      * @param mu  gravitational constant
  75.      */
  76.     public IodGooding(final double mu) {
  77.         this.mu = mu;

  78.         this.rho1 = 0;
  79.         this.rho2 = 0;
  80.         this.rho3 = 0;
  81.     }

  82.     /** Get the range for observation (1).
  83.      *
  84.      * @return the range for observation (1).
  85.      */
  86.     public double getRange1() {
  87.         return rho1 * R;
  88.     }

  89.     /** Get the range for observation (2).
  90.      *
  91.      * @return the range for observation (2).
  92.      */
  93.     public double getRange2() {
  94.         return rho2 * R;
  95.     }

  96.     /** Get the range for observation (3).
  97.      *
  98.      * @return the range for observation (3).
  99.      */
  100.     public double getRange3() {
  101.         return rho3 * R;
  102.     }

  103.     /** Orbit got from three angular observations.
  104.      * @param frame inertial frame for observer coordinates and orbit estimate
  105.      * @param raDec1 first angular observation
  106.      * @param raDec2 second angular observation
  107.      * @param raDec3 third angular observation
  108.      * @param rho1init initial guess of the range problem. range 1, in meters
  109.      * @param rho3init initial guess of the range problem. range 3, in meters
  110.      * @param nRev number of complete revolutions between observation 1 and 3
  111.      * @param direction true if posigrade (short way)
  112.      * @return an estimate of the Keplerian orbit
  113.      * @since 11.0
  114.      */
  115.     public KeplerianOrbit estimate(final Frame frame, final AngularRaDec raDec1,
  116.                                    final AngularRaDec raDec2, final AngularRaDec raDec3,
  117.                                    final double rho1init, final double rho3init,
  118.                                    final int nRev, final boolean direction) {
  119.         return estimate(frame,
  120.                         stationPosition(frame, raDec1),
  121.                         stationPosition(frame, raDec2),
  122.                         stationPosition(frame, raDec3),
  123.                         lineOfSight(raDec1), raDec1.getDate(),
  124.                         lineOfSight(raDec2), raDec2.getDate(),
  125.                         lineOfSight(raDec3), raDec3.getDate(),
  126.                         rho1init, rho3init, nRev, direction);
  127.     }

  128.     /** Orbit got from three angular observations.
  129.      * @param frame inertial frame for observer coordinates and orbit estimate
  130.      * @param raDec1 first angular observation
  131.      * @param raDec2 second angular observation
  132.      * @param raDec3 third angular observation
  133.      * @param rho1init initial guess of the range problem. range 1, in meters
  134.      * @param rho3init initial guess of the range problem. range 3, in meters
  135.      * @return an estimate of the Keplerian orbit
  136.      * @since 11.0
  137.      */
  138.     public KeplerianOrbit estimate(final Frame frame, final AngularRaDec raDec1,
  139.                                    final AngularRaDec raDec2, final AngularRaDec raDec3,
  140.                                    final double rho1init, final double rho3init) {
  141.         return estimate(frame, raDec1, raDec2, raDec3, rho1init, rho3init, 0, true);
  142.     }

  143.     /** Orbit got from Observed Three Lines of Sight (angles only).
  144.      * @param frame inertial frame for observer coordinates and orbit estimate
  145.      * @param O1 Observer position 1
  146.      * @param O2 Observer position 2
  147.      * @param O3 Observer position 3
  148.      * @param lineOfSight1 line of sight 1
  149.      * @param dateObs1 date of observation 1
  150.      * @param lineOfSight2 line of sight 2
  151.      * @param dateObs2 date of observation 2
  152.      * @param lineOfSight3 line of sight 3
  153.      * @param dateObs3 date of observation 3
  154.      * @param rho1init initial guess of the range problem. range 1, in meters
  155.      * @param rho3init initial guess of the range problem. range 3, in meters
  156.      * @param nRev number of complete revolutions between observation1  and 3
  157.      * @param direction true if posigrade (short way)
  158.      * @return an estimate of the Keplerian orbit
  159.      */
  160.     public KeplerianOrbit estimate(final Frame frame, final Vector3D O1, final Vector3D O2, final Vector3D O3,
  161.                                    final Vector3D lineOfSight1, final AbsoluteDate dateObs1,
  162.                                    final Vector3D lineOfSight2, final AbsoluteDate dateObs2,
  163.                                    final Vector3D lineOfSight3, final AbsoluteDate dateObs3,
  164.                                    final double rho1init, final double rho3init, final int nRev,
  165.                                    final boolean direction) {

  166.         this.date1 = dateObs1;

  167.         // normalizing coefficients
  168.         R = FastMath.max(rho1init, rho3init);
  169.         V = FastMath.sqrt(mu / R);
  170.         T = R / V;

  171.         // Initialize Lambert's problem solver for non-dimensional units.
  172.         lambert = new IodLambert(1.);

  173.         this.vObserverPosition1 = O1.scalarMultiply(1. / R);
  174.         this.vObserverPosition2 = O2.scalarMultiply(1. / R);
  175.         this.vObserverPosition3 = O3.scalarMultiply(1. / R);

  176.         final int maxiter = 100; // maximum iter

  177.         // solve the range problem
  178.         solveRangeProblem(frame,
  179.                           rho1init / R, rho3init / R,
  180.                           dateObs3.durationFrom(dateObs1) / T, dateObs2.durationFrom(dateObs1) / T,
  181.                           nRev,
  182.                           direction,
  183.                           lineOfSight1, lineOfSight2, lineOfSight3,
  184.                           maxiter);

  185.         // use the Gibbs problem to get the orbit now that we have three position vectors.
  186.         final IodGibbs gibbs = new IodGibbs(mu);
  187.         final Vector3D p1 = vObserverPosition1.add(lineOfSight1.scalarMultiply(rho1)).scalarMultiply(R);
  188.         final Vector3D p2 = vObserverPosition2.add(lineOfSight2.scalarMultiply(rho2)).scalarMultiply(R);
  189.         final Vector3D p3 = vObserverPosition3.add(lineOfSight3.scalarMultiply(rho3)).scalarMultiply(R);
  190.         return gibbs.estimate(frame, p1, dateObs1, p2, dateObs2, p3, dateObs3);
  191.     }

  192.     /** Orbit got from Observed Three Lines of Sight (angles only).
  193.      * assuming there was less than an half revolution between start and final date
  194.      * @param frame inertial frame for observer coordinates and orbit estimate
  195.      * @param O1 Observer position 1
  196.      * @param O2 Observer position 2
  197.      * @param O3 Observer position 3
  198.      * @param lineOfSight1 line of sight 1
  199.      * @param dateObs1 date of observation 1
  200.      * @param lineOfSight2 line of sight 2
  201.      * @param dateObs2 date of observation 1
  202.      * @param lineOfSight3 line of sight 3
  203.      * @param dateObs3 date of observation 1
  204.      * @param rho1init initial guess of the range problem. range 1, in meters
  205.      * @param rho3init initial guess of the range problem. range 3, in meters
  206.      * @return an estimate of the Keplerian orbit
  207.      */
  208.     public KeplerianOrbit estimate(final Frame frame, final Vector3D O1, final Vector3D O2, final Vector3D O3,
  209.                                    final Vector3D lineOfSight1, final AbsoluteDate dateObs1,
  210.                                    final Vector3D lineOfSight2, final AbsoluteDate dateObs2,
  211.                                    final Vector3D lineOfSight3, final AbsoluteDate dateObs3,
  212.                                    final double rho1init, final double rho3init) {

  213.         return this.estimate(frame, O1, O2, O3, lineOfSight1, dateObs1, lineOfSight2, dateObs2,
  214.                 lineOfSight3, dateObs3, rho1init, rho3init, 0, true);
  215.     }

  216.     /** Solve the range problem when three line of sight are given.
  217.      * @param frame frame to be used (orbit frame)
  218.      * @param rho1init   initial value for range R1, in meters
  219.      * @param rho3init   initial value for range R3, in meters
  220.      * @param T13   time of flight 1->3, in seconds
  221.      * @param T12   time of flight 1->2, in seconds
  222.      * @param nrev number of revolutions
  223.      * @param direction  posigrade (true) or retrograde
  224.      * @param lineOfSight1  line of sight 1
  225.      * @param lineOfSight2  line of sight 2
  226.      * @param lineOfSight3  line of sight 3
  227.      * @param maxIterations         max iter
  228.      * @return nothing
  229.      */
  230.     private boolean solveRangeProblem(final Frame frame,
  231.                                       final double rho1init, final double rho3init,
  232.                                       final double T13, final double T12,
  233.                                       final int nrev,
  234.                                       final boolean direction,
  235.                                       final Vector3D lineOfSight1,
  236.                                       final Vector3D lineOfSight2,
  237.                                       final Vector3D lineOfSight3,
  238.                                       final int maxIterations) {
  239.         final double ARBF = 1e-6;   // finite differences step
  240.         boolean withHalley = true;  // use Halley's method
  241.         final double cvtol = 1e-14; // convergence tolerance

  242.         rho1 = rho1init;
  243.         rho3 = rho3init;


  244.         int iter = 0;
  245.         double stoppingCriterion = 10 * cvtol;
  246.         while (iter < maxIterations && FastMath.abs(stoppingCriterion) > cvtol)  {
  247.             facFiniteDiff = ARBF;

  248.             // proposed in the original algorithm by Gooding.
  249.             // We change the threshold to maxIterations / 2.
  250.             if (iter >= (maxIterations / 2)) {
  251.                 withHalley = true;
  252.             }

  253.             // tentative position for R2
  254.             final Vector3D P2 = getPositionOnLoS2(frame,
  255.                                                   lineOfSight1, rho1,
  256.                                                   lineOfSight3, rho3,
  257.                                                   T13, T12, nrev, direction);

  258.             if (P2 == null) {
  259.                 modifyIterate(lineOfSight1, lineOfSight2, lineOfSight3);
  260.             } else {
  261.                 //
  262.                 R2 = P2.getNorm();

  263.                 // compute current line of sight for (2) and the associated range
  264.                 final Vector3D C = P2.subtract(vObserverPosition2);
  265.                 rho2 = C.getNorm();

  266.                 final double R10 = R1;
  267.                 final double R30 = R3;

  268.                 // indicate how close we are to the direction of sight for measurement (2)
  269.                 // for convergence test
  270.                 final double CR = lineOfSight2.dotProduct(C);

  271.                 // construct a basis and the function f and g.
  272.                 // Specifically, f is the P-coordinate and g the N-coordinate.
  273.                 // They should be zero when line of sight 2 and current direction for 2 from O2 are aligned.
  274.                 final Vector3D u = lineOfSight2.crossProduct(C);
  275.                 final Vector3D P = (u.crossProduct(lineOfSight2)).normalize();
  276.                 final Vector3D ENt = lineOfSight2.crossProduct(P);

  277.                 // if ENt is zero we have a solution!
  278.                 final double ENR = ENt.getNorm();
  279.                 if (ENR == 0.) {
  280.                     return true;
  281.                 }

  282.                 //Normalize EN
  283.                 final Vector3D EN = ENt.normalize();

  284.                 // Coordinate along 'F function'
  285.                 final double Fc = P.dotProduct(C);
  286.                 //Gc = EN.dotProduct(C);

  287.                 // Now get partials, by finite differences
  288.                 final double[] FD = new double[2];
  289.                 final double[] GD = new double[2];
  290.                 computeDerivatives(frame,
  291.                                    rho1, rho3,
  292.                                    R10, R30,
  293.                                    lineOfSight1, lineOfSight3,
  294.                                    P, EN,
  295.                                    Fc,
  296.                                    T13, T12,
  297.                                    withHalley,
  298.                                    nrev,
  299.                                    direction,
  300.                                    FD, GD);

  301.                 // terms of the Jacobian
  302.                 final double fr1 = FD[0];
  303.                 final double fr3 = FD[1];
  304.                 final double gr1 = GD[0];
  305.                 final double gr3 = GD[1];
  306.                 // determinant of the Jacobian matrix
  307.                 final double detj = fr1 * gr3 - fr3 * gr1;

  308.                 // compute the Newton step
  309.                 D3 = -gr3 * Fc / detj;
  310.                 D1 = gr1 * Fc / detj;

  311.                 // update current values of ranges
  312.                 rho1 = rho1 + D3;
  313.                 rho3 = rho3 + D1;

  314.                 // convergence tests
  315.                 final double den = FastMath.max(CR, R2);
  316.                 stoppingCriterion = Fc / den;
  317.             }

  318.             ++iter;
  319.         } // end while

  320.         return true;
  321.     }

  322.     /** Change the current iterate if Lambert's problem solver failed to find a solution.
  323.      *
  324.      * @param lineOfSight1 line of sight 1
  325.      * @param lineOfSight2 line of sight 2
  326.      * @param lineOfSight3 line of sight 3
  327.      */
  328.     private void modifyIterate(final Vector3D lineOfSight1,
  329.                                final Vector3D lineOfSight2,
  330.                                final Vector3D lineOfSight3) {
  331.         // This is a modifier proposed in the initial paper of Gooding.
  332.         // Try to avoid Lambert-fail, by common-perpendicular starters
  333.         final Vector3D R13 = vObserverPosition3.subtract(vObserverPosition1);
  334.         D1 = R13.dotProduct(lineOfSight1);
  335.         D3 = R13.dotProduct(lineOfSight3);
  336.         final double D2 = lineOfSight1.dotProduct(lineOfSight3);
  337.         final double D4 = 1. - D2 * D2;
  338.         rho1 = FastMath.max((D1 - D3 * D2) / D4, 0.);
  339.         rho3 = FastMath.max((D1 * D2 - D3) / D4, 0.);
  340.     }

  341.     /** Compute the derivatives by finite-differences for the range problem.
  342.      * Specifically, we are trying to solve the problem:
  343.      *      f(x, y) = 0
  344.      *      g(x, y) = 0
  345.      * So, in a Newton-Raphson process, we would need the derivatives:
  346.      *  fx, fy, gx, gy
  347.      * Enventually,
  348.      *    dx =-f*gy / D
  349.      *    dy = f*gx / D
  350.      * where D is the determinant of the Jacobian matrix.
  351.      *
  352.      * @param frame frame to be used (orbit frame)
  353.      * @param x    current range 1
  354.      * @param y    current range 3
  355.      * @param R10   current radius 1
  356.      * @param R30   current radius 3
  357.      * @param lineOfSight1  line of sight
  358.      * @param lineOfSight3  line of sight
  359.      * @param Pin   basis vector
  360.      * @param Ein   basis vector
  361.      * @param F     value of the f-function
  362.      * @param T13   time of flight 1->3, in seconds
  363.      * @param T12   time of flight 1->2, in seconds
  364.      * @param withHalley    use Halley iterative method
  365.      * @param nrev  number of revolutions
  366.      * @param direction direction of motion
  367.      * @param FD    derivatives of f wrt (rho1, rho3) by finite differences
  368.      * @param GD    derivatives of g wrt (rho1, rho3) by finite differences
  369.      */
  370.     private void computeDerivatives(final Frame frame,
  371.                                     final double x, final double y,
  372.                                     final double R10, final double R30,
  373.                                     final Vector3D lineOfSight1, final Vector3D lineOfSight3,
  374.                                     final Vector3D Pin,
  375.                                     final Vector3D Ein,
  376.                                     final double F,
  377.                                     final double T13, final double T12,
  378.                                     final boolean withHalley,
  379.                                     final int nrev,
  380.                                     final boolean direction,
  381.                                     final double[] FD, final double[] GD) {

  382.         final Vector3D P = Pin.normalize();
  383.         final Vector3D EN = Ein.normalize();

  384.         // Now get partials, by finite differences
  385.         // steps for the differentiation
  386.         final double dx = facFiniteDiff * x;
  387.         final double dy = facFiniteDiff * y;

  388.         final Vector3D Cm1 = getPositionOnLoS2 (frame,
  389.                                                 lineOfSight1, x - dx,
  390.                                                 lineOfSight3, y,
  391.                                                 T13, T12, nrev, direction).subtract(vObserverPosition2);

  392.         final double Fm1 = P.dotProduct(Cm1);
  393.         final double Gm1 = EN.dotProduct(Cm1);

  394.         final Vector3D Cp1 = getPositionOnLoS2 (frame,
  395.                                                 lineOfSight1, x + dx,
  396.                                                 lineOfSight3, y,
  397.                                                 T13, T12, nrev, direction).subtract(vObserverPosition2);

  398.         final double Fp1  = P.dotProduct(Cp1);
  399.         final double Gp1 = EN.dotProduct(Cp1);

  400.         // derivatives df/drho1 and dg/drho1
  401.         final double Fx = (Fp1 - Fm1) / (2. * dx);
  402.         final double Gx = (Gp1 - Gm1) / (2. * dx);

  403.         final Vector3D Cm3 = getPositionOnLoS2 (frame,
  404.                                                 lineOfSight1, x,
  405.                                                 lineOfSight3, y - dy,
  406.                                                 T13, T12, nrev, direction).subtract(vObserverPosition2);

  407.         final double Fm3 = P.dotProduct(Cm3);
  408.         final double Gm3 = EN.dotProduct(Cm3);

  409.         final Vector3D Cp3 = getPositionOnLoS2 (frame,
  410.                                                 lineOfSight1, x,
  411.                                                 lineOfSight3, y + dy,
  412.                                                 T13, T12, nrev, direction).subtract(vObserverPosition2);

  413.         final double Fp3 = P.dotProduct(Cp3);
  414.         final double Gp3 = EN.dotProduct(Cp3);

  415.         // derivatives df/drho3 and dg/drho3
  416.         final double Fy = (Fp3 - Fm3) / (2. * dy);
  417.         final double Gy = (Gp3 - Gm3) / (2. * dy);
  418.         final double detJac = Fx * Gy - Fy * Gx;

  419.         // Coefficients for the classical Newton-Raphson iterative method
  420.         FD[0] = Fx;
  421.         FD[1] = Fy;
  422.         GD[0] = Gx;
  423.         GD[1] = Gy;

  424.         // Modified Newton-Raphson process, with Halley's method to have cubic convergence.
  425.         // This requires computing second order derivatives.
  426.         if (withHalley) {
  427.             //
  428.             final double hrho1Sq = dx * dx;
  429.             final double hrho3Sq = dy * dy;

  430.             // Second order derivatives: d^2f / drho1^2 and d^2g / drho3^2
  431.             final double Fxx = (Fp1 + Fm1 - 2 * F) / hrho1Sq;
  432.             final double Gxx = (Gp1 + Gm1 - 2 * F) / hrho1Sq;
  433.             final double Fyy = (Fp3 + Fp3 - 2 * F) / hrho3Sq;
  434.             final double Gyy = (Gm3 + Gm3 - 2 * F) / hrho3Sq;

  435.             final Vector3D Cp13 = getPositionOnLoS2 (frame,
  436.                                                      lineOfSight1, x + dx,
  437.                                                      lineOfSight3, y + dy,
  438.                                                      T13, T12, nrev, direction).subtract(vObserverPosition2);

  439.             // f function value at (x1+dx1, x3+dx3)
  440.             final double Fp13 = P.dotProduct(Cp13);
  441.             // g function value at (x1+dx1, x3+dx3)
  442.             final double Gp13 = EN.dotProduct(Cp13);

  443.             final Vector3D Cm13 = getPositionOnLoS2 (frame,
  444.                                                      lineOfSight1, x - dx,
  445.                                                      lineOfSight3, y - dy,
  446.                                                      T13, T12, nrev, direction).subtract(vObserverPosition2);

  447.             // f function value at (x1-dx1, x3-dx3)
  448.             final double Fm13 = P.dotProduct(Cm13);
  449.             // g function value at (x1-dx1, x3-dx3)
  450.             final double Gm13 = EN.dotProduct(Cm13);

  451.             // Second order derivatives: d^2f / drho1drho3 and d^2g / drho1drho3
  452.             //double Fxy = Fp13 / (dx * dy) - (Fx / dy + Fy / dx) -
  453.             //                0.5 * (Fxx * dx / dy + Fyy * dy / dx);
  454.             //double Gxy = Gp13 / (dx * dy) - (Gx / dy + Gy / dx) -
  455.             //                0.5 * (Gxx * dx / dy + Gyy * dy / dx);
  456.             final double Fxy = (Fp13 + Fm13) / (2 * dx * dy) - 0.5 * (Fxx * dx / dy + Fyy * dy / dx) - F / (dx * dy);
  457.             final double Gxy = (Gp13 + Gm13) / (2 * dx * dy) - 0.5 * (Gxx * dx / dy + Gyy * dy / dx) - F / (dx * dy);

  458.             // delta Newton Raphson, 1st order step
  459.             final double dx3NR = -Gy * F / detJac;
  460.             final double dx1NR = Gx * F / detJac;

  461.             // terms of the Jacobian, considering the development, after linearization
  462.             // of the second order Taylor expansion around the Newton Raphson iterate:
  463.             // (fx + 1/2 * fxx * dx* + 1/2 * fxy * dy*) * dx
  464.             //      + (fy + 1/2 * fyy * dy* + 1/2 * fxy * dx*) * dy
  465.             // where: dx* and dy* would be the step of the Newton raphson process.
  466.             final double FxH = Fx + 0.5 * (Fxx * dx3NR + Fxy * dx1NR);
  467.             final double FyH = Fy + 0.5 * (Fxy * dx3NR + Fxx * dx1NR);
  468.             final double GxH = Gx + 0.5 * (Gxx * dx3NR + Gxy * dx1NR);
  469.             final double GyH = Gy + 0.5 * (Gxy * dx3NR + Gyy * dx1NR);

  470.             // New Halley's method "Jacobian"
  471.             FD[0] = FxH;
  472.             FD[1] = FyH;
  473.             GD[0] = GxH;
  474.             GD[1] = GyH;
  475.         }
  476.     }

  477.     /** Calculate the position along sight-line.
  478.      * @param frame frame to be used (orbit frame)
  479.      * @param E1 line of sight 1
  480.      * @param RO1 distance along E1
  481.      * @param E3 line of sight 3
  482.      * @param RO3 distance along E3
  483.      * @param T12   time of flight
  484.      * @param T13   time of flight
  485.      * @param nRev number of revolutions
  486.      * @param posigrade direction of motion
  487.      * @return (R2-O2)
  488.      */
  489.     private Vector3D getPositionOnLoS2(final Frame frame,
  490.                                        final Vector3D E1, final double RO1,
  491.                                        final Vector3D E3, final double RO3,
  492.                                        final double T13, final double T12,
  493.                                        final int nRev, final boolean posigrade) {
  494.         final Vector3D P1 = vObserverPosition1.add(E1.scalarMultiply(RO1));
  495.         R1 = P1.getNorm();

  496.         final Vector3D P3 = vObserverPosition3.add(E3.scalarMultiply(RO3));
  497.         R3 = P3.getNorm();

  498.         final Vector3D P13 = P1.crossProduct(P3);

  499.         // sweep angle
  500.         // (Fails only if either R1 or R2 is zero)
  501.         double TH = FastMath.atan2(P13.getNorm(), P1.dotProduct(P3));

  502.         // compute the number of revolutions
  503.         if (!posigrade) {
  504.             TH = 2 * FastMath.PI - TH;
  505.         }

  506.         // Solve the Lambert's problem to get the velocities at endpoints
  507.         final double[] V1 = new double[2];
  508.         // work with non-dimensional units (MU=1)
  509.         final boolean exitflag = lambert.solveLambertPb(R1, R3, TH, T13, nRev, V1);

  510.         if (exitflag) {
  511.             // basis vectors
  512.             final Vector3D Pn = P1.crossProduct(P3);
  513.             final Vector3D Pt = Pn.crossProduct(P1);

  514.             // tangential velocity norm
  515.             double RT = Pt.getNorm();
  516.             if (!posigrade) {
  517.                 RT = -RT;
  518.             }

  519.             // velocity vector at P1
  520.             final Vector3D Vel1 = new  Vector3D(V1[0] / R1, P1, V1[1] / RT, Pt);

  521.             // estimate the position at the second observation time
  522.             // propagate (P1, V1) during TAU + T12 to get (P2, V2)
  523.             final Vector3D P2 = propagatePV(frame, P1, Vel1, T12);

  524.             return P2;
  525.         }

  526.         return null;
  527.     }

  528.     /** Propagate a solution (Kepler).
  529.      * @param frame frame to be used (orbit frame)
  530.      * @param P1    initial position vector
  531.      * @param V1    initial velocity vector
  532.      * @param tau   propagation time
  533.      * @return final position vector
  534.      */
  535.     private Vector3D propagatePV(final Frame frame, final Vector3D P1, final Vector3D V1, final double tau) {
  536.         final PVCoordinates pv1 = new PVCoordinates(P1, V1);
  537.         // create a Keplerian orbit. Assume MU = 1.
  538.         final KeplerianOrbit orbit = new KeplerianOrbit(pv1, frame, date1, 1.);
  539.         return orbit.shiftedBy(tau).getPVCoordinates().getPosition();
  540.     }

  541.     /**
  542.      * Calculates the line of sight vector.
  543.      * @param alpha right ascension angle, in radians
  544.      * @param delta declination angle, in radians
  545.      * @return the line of sight vector
  546.      * @since 11.0
  547.      */
  548.     public static Vector3D lineOfSight(final double alpha, final double delta) {
  549.         return new Vector3D(FastMath.cos(delta) * FastMath.cos(alpha),
  550.                             FastMath.cos(delta) * FastMath.sin(alpha),
  551.                             FastMath.sin(delta));
  552.     }

  553.     /**
  554.      * Calculate the line of sight vector from an AngularRaDec measurement.
  555.      * @param raDec measurement
  556.      * @return the line of sight vector
  557.      * @since 11.0
  558.      */
  559.     public static Vector3D lineOfSight(final AngularRaDec raDec) {

  560.         // Observed values
  561.         final double[] observed = raDec.getObservedValue();

  562.         // Return
  563.         return lineOfSight(observed[0], observed[1]);

  564.     }

  565.     /**
  566.      * Get the station position from the right ascension / declination measurement.
  567.      * @param frame inertial frame for station posiiton and orbit estimate
  568.      * @param raDec measurement
  569.      * @return the station position
  570.      */
  571.     private static Vector3D stationPosition(final Frame frame, final AngularRaDec raDec) {
  572.         return raDec.getStation().getBaseFrame().getPVCoordinates(raDec.getDate(), frame).getPosition();
  573.     }

  574. }