Example #1
0
            public IEnumerator <LandingTrajectory> GetEnumerator()
            {
//                m.Log("Calculating initial orbit eccentricity...");//debug
                var tPos = m.CFG.Target.OrbPos(m.Body);
                var UT   = m.VSL.Physics.UT +
                           TrajectoryCalculator.AngleDelta(m.VesselOrbit, tPos, m.VSL.Physics.UT) / 360 * m.VesselOrbit.period;

                if (UT < m.VSL.Physics.UT)
                {
                    UT += m.VesselOrbit.period;
                }
                var vPos   = m.VesselOrbit.getRelativePositionAtUT(UT);
                var vVel   = m.VesselOrbit.getOrbitalVelocityAtUT(UT);
                var incl   = Math.Abs(90 - Utils.Angle2(tPos, m.VesselOrbit.GetOrbitNormal()));
                var ini_dV = TrajectoryCalculator.dV4Pe(m.VesselOrbit, (m.Body.Radius + m.TargetAltitude * 0.9), UT);

                ini_dV = QuaternionD.AngleAxis(incl, vPos) * (ini_dV + vVel);
                var dir  = -ini_dV.normalized;
                var maxV = ini_dV.magnitude;

                ini_dV -= vVel;
                Best    = new LandingTrajectory(m.VSL, ini_dV, UT, m.CFG.Target, m.TargetAltitude);
                yield return(Best);

                //if there's not enough fuel, just go with the smallest maneuver possible
                if (Best.FullManeuver)
                {
                    //search for the best trajectory using current comparer
                    var start = Best;
                    var bestV = 0.0;
                    var dV    = maxV / 10;
                    var V     = dV;
                    while (Math.Abs(dV) > TrajectoryCalculator.C.dVtol)
                    {
                        var cur = new LandingTrajectory(m.VSL, start.ManeuverDeltaV + dir * V, start.StartUT, m.CFG.Target, start.TargetAltitude);
//                        m.Log("V {}, dV {}, is better {}\ncur {}\nbest {}",
//                              V, dV, comparer.isBetter(cur, Best), cur, Best);//debug
                        if (comparer.isBetter(cur, Best))
                        {
                            Best  = cur;
                            bestV = V;
                        }
                        V += dV;
                        if (V < 0 || V > maxV || cur != Best)
                        {
                            dV /= -2.1;
                            V   = bestV;
                        }
                        yield return(cur);
                    }
                }
                m.initialEcc = Best.Orbit.eccentricity;
//                m.Log("initialEcc: {}", m.initialEcc);//debug
            }