Пример #1
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)
            {
            }
        }