コード例 #1
0
        public static double CalculateHohmannTransferDeltaV(SimpleOrbit orbit1, SimpleOrbit orbit2)
        {
            SimpleOrbit fastestPeriapsisOrbit, slowestPeriapsisOrbit, transferOrbit;
            double      deltaV = 0.0;

            if (orbit1.ParentBody != orbit2.ParentBody)
            {
                throw new ArgumentException("Input orbits must have same parent body.");
            }

            if (orbit1.PeriapsisSpeed > orbit2.PeriapsisSpeed)
            {
                fastestPeriapsisOrbit = orbit1;
                slowestPeriapsisOrbit = orbit2;
            }
            else
            {
                fastestPeriapsisOrbit = orbit2;
                slowestPeriapsisOrbit = orbit1;
            }

            SimpleOrbitBuilder transferOrbitBuilder = new SimpleOrbitBuilder(orbit1.ParentBody);

            transferOrbitBuilder.SetPeriapsis(fastestPeriapsisOrbit.Periapsis);
            transferOrbitBuilder.SetApoapsis(slowestPeriapsisOrbit.Periapsis);
            transferOrbit = transferOrbitBuilder.Build();

            deltaV += Math.Abs(transferOrbit.PeriapsisSpeed - fastestPeriapsisOrbit.PeriapsisSpeed);
            deltaV += Math.Abs(slowestPeriapsisOrbit.PeriapsisSpeed - transferOrbit.ApoapsisSpeed);

            return(deltaV);
        }
        /// <summary>
        /// Will set the GUI text fields based on the input orbit.
        /// </summary>
        /// <param name="orbit">An orbit that was calculated.</param>
        private void ParseOrbit(SimpleOrbit orbit)
        {
            if (!lockApoapsis)
            {
                apoapsisText = useAltitideAspides ? orbit.ApoapsisAltitude.ToString() : orbit.Apoapsis.ToString();
            }

            if (!lockPeriapsis)
            {
                periapsisText = useAltitideAspides ? orbit.PeriapsisAltitude.ToString() : orbit.Periapsis.ToString();
            }

            if (!lockEccentricity)
            {
                eccentricityText = orbit.Eccentricity.ToString();
            }
            if (!lockSMA)
            {
                smaText = orbit.SemiMajorAxis.ToString();
            }
            if (!lockPeriod)
            {
                periodText = orbit.OrbitalPeriod.ToString();
            }
        }
        private void RenderHohmannTransferArea()
        {
            // The Orbit 1 Save button.
            GUILayout.BeginHorizontal();
            if (currentOrbit == null)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Save as Orbit 1", GUILayout.Width(SaveOrbitButtonWidth)))
            {
                savedOrbit1 = currentOrbit;
            }
            GUI.enabled = true;
            if (savedOrbit1 != null)
            {
                if (GUILayout.Button("C", GUILayout.Width(CharButtonWidth)))
                {
                    savedOrbit1 = null;
                }
                GUILayout.Label(savedOrbit1.ToString(useAltitideAspides));
            }
            GUILayout.EndHorizontal();

            // The Orbit 2 Save button.
            GUILayout.BeginHorizontal();
            if (currentOrbit == null)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Save as Orbit 2", GUILayout.Width(SaveOrbitButtonWidth)))
            {
                savedOrbit2 = currentOrbit;
            }
            GUI.enabled = true;
            if (savedOrbit2 != null)
            {
                if (GUILayout.Button("C", GUILayout.Width(CharButtonWidth)))
                {
                    savedOrbit2 = null;
                }
                GUILayout.Label(savedOrbit2.ToString(useAltitideAspides));
            }
            GUILayout.EndHorizontal();

            // Calculate the delta-V of transfer if valid.
            if (savedOrbit1 != null && savedOrbit2 != null)
            {
                if (savedOrbit1.ParentBody == savedOrbit2.ParentBody)
                {
                    try
                    {
                        double hohmannTransferDeltaV = SimpleOrbit.CalculateHohmannTransferDeltaV(savedOrbit1, savedOrbit2);
                        GUILayout.Label("Transfer Δv: " + SOCUtilis.ParseOrbitElement(hohmannTransferDeltaV, SimpleOrbit.ScalerType.Speed));
                    }
                    catch (ArgumentException e)
                    {
                        GUILayout.Label("Error: " + e.Message);
                    }
                }
                else
                {
                    GUILayout.Label("Parent bodies of saved orbits do not match.");
                }
            }
        }