Beispiel #1
0
        private void SetScale()
        {
            PlanetSystem.Models.Utilities.Point dummy = new PlanetSystem.Models.Utilities.Point(0, 0, 0);
            var    bodies           = currentPlanetarySystem.GetAllBodies();
            double greatestDistance = Physics.GetGreatestDistance(bodies, out dummy);

            scaleFactor = canvasPanel.Width / (greatestDistance * 2.5);
        }
Beispiel #2
0
        private void simulateButton_Click(object sender, EventArgs e)
        {
            try
            {
                var stepCount    = int.Parse(stepsCountBox.Text);
                var stepDuration = double.Parse(stepDurationBox.Text);
                List <List <PlanetSystem.Models.Utilities.Point> > positions = new List <List <PlanetSystem.Models.Utilities.Point> >();
                var startingPositions = currentPlanetarySystem.GetAllPositions();
                startingPositions.ForEach(p => p = new PlanetSystem.Models.Utilities.Point(p));
                positions.Add(startingPositions);

                double greatestDistance;
                PlanetSystem.Models.Utilities.Point centerPointCandidate = new PlanetSystem.Models.Utilities.Point(0, 0, 0);
                greatestDistance = Physics.GetGreatestDistance(currentPlanetarySystem.GetAllBodies(), out centerPointCandidate);

                PlanetSystem.Models.Utilities.Point centerPoint = new PlanetSystem.Models.Utilities.Point(0, 0, 0);

                for (int i = 0; i < stepCount; i++)
                {
                    currentPlanetarySystem.AdvanceTime(currentPlanetarySystem.GetAllBodies(), stepDuration);
                    var currentPositions = currentPlanetarySystem.GetAllPositions();
                    currentPositions.ForEach(p => p = new PlanetSystem.Models.Utilities.Point(p));
                    positions.Add(currentPositions);
                    var currentDistance = Physics.GetGreatestDistance(currentPlanetarySystem.GetAllBodies(), out centerPointCandidate);
                    if (currentDistance > greatestDistance)
                    {
                        greatestDistance = currentDistance;
                        centerPoint      = new PlanetSystem.Models.Utilities.Point(centerPointCandidate);
                    }
                }

                var curves = GetCurvesFromPositions(positions);
                curves = ScalePositions(curves, greatestDistance, canvasPanel.Width);
                var drawableCurves = ConvertToDrawableCurves(curves, planeOfGraph,
                                                             new System.Drawing.Point(canvasPanel.Width / 2, canvasPanel.Height / 2));
                DrawCurves(drawableCurves);
                Refresh();
            }
            catch (Exception exc)
            {
            }
        }
Beispiel #3
0
        private void setOrbitButon_Click(object sender, EventArgs e)
        {
            try
            {
                double coveredAngle = 0;
                try
                {
                    coveredAngle = double.Parse(setOrbitCoveredAngleBox.Text);
                }
                catch (Exception exc)
                { }
                double orbitParameter = MathUtilities.ParseFromExpNotation(
                    double.Parse(setOrbitParameterBox.Text),
                    int.Parse(setOrbitParameterEBox.Text));
                if (selectedBody is Planet)
                {
                    Planet planet = (Planet)selectedBody;
                    if (setOrbitRadiusRadio.Checked)
                    {
                        Vector startingVelocity = new Vector(planet.Velocity);
                        PlanetSystem.Models.Utilities.Point startingPoint = new PlanetSystem.Models.Utilities.Point(planet.Center);
                        if (setOrbitRadiusRadio.Checked)
                        {
                            Physics.EnterOrbitByGivenRadius(ref planet, currentPlanetarySystem.Star, orbitParameter, coveredAngle);
                        }
                        else
                        {
                            Physics.EnterOrbitByGivenSpeed(ref planet, currentPlanetarySystem.Star, orbitParameter, coveredAngle);
                        }
                        Vector deltaVelocity = planet.Velocity - startingVelocity;
                        PlanetSystem.Models.Utilities.Point deltaPoint = planet.Center - startingPoint;
                        planet.Moons.ToList().ForEach(m =>
                        {
                            Physics.AddVelocityToBody(ref m, deltaVelocity);
                            m.Center = new PlanetSystem.Models.Utilities.Point(
                                m.Center.X + deltaPoint.X,
                                m.Center.Y + deltaPoint.Y,
                                m.Center.X + deltaPoint.Z
                                );
                        });
                    }
                    else
                    {
                        Vector startingVelocity = new Vector(planet.Velocity);
                        PlanetSystem.Models.Utilities.Point startingPoint = new PlanetSystem.Models.Utilities.Point(planet.Center);
                        if (setOrbitRadiusRadio.Checked)
                        {
                            Physics.EnterOrbitByGivenSpeed(ref planet, currentPlanetarySystem.Star, orbitParameter, coveredAngle);
                        }
                        else
                        {
                            Physics.EnterOrbitByGivenSpeed(ref planet, currentPlanetarySystem.Star, orbitParameter, coveredAngle);
                        }
                        Vector deltaVelocity = planet.Velocity - startingVelocity;
                        PlanetSystem.Models.Utilities.Point deltaPoint = planet.Center - startingPoint;
                        planet.Moons.ToList().ForEach(m =>
                        {
                            Physics.AddVelocityToBody(ref m, deltaVelocity);
                            m.Center = new PlanetSystem.Models.Utilities.Point(
                                m.Center.X + deltaPoint.X,
                                m.Center.Y + deltaPoint.Y,
                                m.Center.X + deltaPoint.Z
                                );
                        });
                    }
                }
                else if (selectedBody is Moon)
                {
                    Moon moon = (Moon)selectedBody;
                    if (setOrbitRadiusRadio.Checked)
                    {
                        Physics.EnterOrbitByGivenRadius(ref moon, moon.Planet, orbitParameter, coveredAngle);
                    }
                    else
                    {
                        Physics.EnterOrbitByGivenSpeed(ref moon, moon.Planet, orbitParameter, coveredAngle);
                    }
                }
                else if (selectedBody is Asteroid)
                {
                    Asteroid asteroid     = (Asteroid)selectedBody;
                    var      bodies       = currentPlanetarySystem.GetAllBodies();
                    var      primaryQuery = from p in bodies
                                            where p.Name == setOrbitPrimeBox.SelectedText
                                            select p;

                    AstronomicalBody primary = primaryQuery.FirstOrDefault();
                    if (setOrbitRadiusRadio.Checked)
                    {
                        Physics.EnterOrbitByGivenRadius(ref asteroid, primary, orbitParameter, coveredAngle);
                    }
                    else
                    {
                        Physics.EnterOrbitByGivenSpeed(ref asteroid, primary, orbitParameter, coveredAngle);
                    }
                }
                else if (selectedBody is ArtificialObject)
                {
                    ArtificialObject artificialObject = (ArtificialObject)selectedBody;
                    var bodies       = currentPlanetarySystem.GetAllBodies();
                    var primaryQuery = from p in bodies
                                       where p.Name == setOrbitPrimeBox.SelectedText
                                       select p;

                    AstronomicalBody primary = primaryQuery.FirstOrDefault();
                    if (setOrbitRadiusRadio.Checked)
                    {
                        Physics.EnterOrbitByGivenRadius(ref artificialObject, primary, orbitParameter, coveredAngle);
                    }
                    else
                    {
                        Physics.EnterOrbitByGivenSpeed(ref artificialObject, primary, orbitParameter, coveredAngle);
                    }
                }
                else
                {
                    var bodies       = currentPlanetarySystem.GetAllBodies();
                    var primaryQuery = from p in bodies
                                       where p.Name == setOrbitPrimeBox.SelectedText
                                       select p;

                    AstronomicalBody primary = primaryQuery.FirstOrDefault();
                    if (setOrbitRadiusRadio.Checked)
                    {
                        Physics.EnterOrbitByGivenRadius(ref selectedBody, primary, orbitParameter, coveredAngle);
                    }
                    else
                    {
                        Physics.EnterOrbitByGivenSpeed(ref selectedBody, primary, orbitParameter, coveredAngle);
                    }
                }
                Refresh();
            }
            catch (Exception exc)
            {
            }
        }
Beispiel #4
0
 private void CenterPositions(
     ref List <List <PlanetSystem.Models.Utilities.Point> > positions,
     PlanetSystem.Models.Utilities.Point centerPoint)
 {
     positions.ForEach(l => { PlanetSystem.Models.Utilities.Point.OffsetBy(l, centerPoint.GetOpposite()); });
 }