Exemplo n.º 1
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = 0;

            if (!target.NormalTargetExists)
            {
                throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception1"));//must select a target for the bi-impulsive transfer.
            }
            else if (o.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception2"));//target for bi-impulsive transfer must be in the same sphere of influence.
            }

            Vector3d dV;

            Orbit targetOrbit = target.TargetOrbit;

            if (periodOffset != 0)
            {
                targetOrbit = target.TargetOrbit.Clone();
                targetOrbit.MutatedOrbit(periodOffset: periodOffset);
            }

            if (simpleTransfer)
            {
                dV = OrbitalManeuverCalculator.DeltaVAndTimeForHohmannTransfer(o, targetOrbit, universalTime, out UT);
            }
            else
            {
                if (timeSelector.timeReference == TimeReference.COMPUTED)
                {
                    dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, targetOrbit, universalTime, out UT, intercept_only: intercept_only);
                }
                else
                {
                    var    anExists = o.AscendingNodeExists(target.TargetOrbit);
                    var    dnExists = o.DescendingNodeExists(target.TargetOrbit);
                    double anTime   = o.TimeOfAscendingNode(target.TargetOrbit, universalTime);
                    double dnTime   = o.TimeOfDescendingNode(target.TargetOrbit, universalTime);

                    if (timeSelector.timeReference == TimeReference.REL_ASCENDING)
                    {
                        if (!anExists)
                        {
                            throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception3"));//ascending node with target doesn't exist.
                        }
                        UT = anTime;
                    }
                    else if (timeSelector.timeReference == TimeReference.REL_DESCENDING)
                    {
                        if (!dnExists)
                        {
                            throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception4"));//descending node with target doesn't exist.
                        }
                        UT = dnTime;
                    }
                    else if (timeSelector.timeReference == TimeReference.REL_NEAREST_AD)
                    {
                        if (!anExists && !dnExists)
                        {
                            throw new OperationException(Localizer.Format("#MechJeb_Hohm_Exception5"));//neither ascending nor descending node with target exists.
                        }
                        if (!dnExists || anTime <= dnTime)
                        {
                            UT = anTime;
                        }
                        else
                        {
                            UT = dnTime;
                        }
                    }

                    UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
                    dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, targetOrbit, UT, out UT, intercept_only: intercept_only, fixed_ut: true);
                }
            }

            return(new ManeuverParameters(dV, UT));
        }
Exemplo n.º 2
0
        public override ManeuverParameters MakeNodeImpl(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            double UT = 0;

            if (!target.NormalTargetExists)
            {
                throw new OperationException("must select a target for the bi-impulsive transfer.");
            }
            else if (o.referenceBody != target.TargetOrbit.referenceBody)
            {
                throw new OperationException("target for bi-impulsive transfer must be in the same sphere of influence.");
            }

            var    anExists = o.AscendingNodeExists(target.TargetOrbit);
            var    dnExists = o.DescendingNodeExists(target.TargetOrbit);
            double anTime   = o.TimeOfAscendingNode(target.TargetOrbit, universalTime);
            double dnTime   = o.TimeOfDescendingNode(target.TargetOrbit, universalTime);

            if (timeSelector.timeReference == TimeReference.REL_ASCENDING)
            {
                if (!anExists)
                {
                    throw new OperationException("ascending node with target doesn't exist.");
                }
                UT = anTime;
            }
            else if (timeSelector.timeReference == TimeReference.REL_DESCENDING)
            {
                if (!dnExists)
                {
                    throw new OperationException("descending node with target doesn't exist.");
                }
                UT = dnTime;
            }
            else if (timeSelector.timeReference == TimeReference.REL_NEAREST_AD)
            {
                if (!anExists && !dnExists)
                {
                    throw new OperationException("neither ascending nor descending node with target exists.");
                }
                if (!dnExists || anTime <= dnTime)
                {
                    UT = anTime;
                }
                else
                {
                    UT = dnTime;
                }
            }
            else if (timeSelector.timeReference != TimeReference.COMPUTED)
            {
                UT = timeSelector.ComputeManeuverTime(o, universalTime, target);
            }

            Vector3d dV;

            if (timeSelector.timeReference == TimeReference.COMPUTED)
            {
                dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, target.TargetOrbit, universalTime, out UT, intercept_only: intercept_only);
            }
            else
            {
                dV = OrbitalManeuverCalculator.DeltaVAndTimeForBiImpulsiveAnnealed(o, target.TargetOrbit, UT, out UT, intercept_only: intercept_only, fixed_ut: true);
            }

            return(new ManeuverParameters(dV, UT));
        }