Beispiel #1
0
        static double GravConst = 6.6740831e-11; // N * m²/kg²     G in equations

        public static List <Tuple <double, double, double> > IteratePosition(SpaceItem moving_item, Dictionary <string, SpaceItem> list, int iterations)
        {
            Tuple <double, double, double>         velocity  = moving_item.velocity;
            Tuple <double, double, double>         position  = moving_item.position;
            List <Tuple <double, double, double> > positions = new List <Tuple <double, double, double> >();

            for (int i = 0; i < iterations; i++)
            {
                foreach (KeyValuePair <string, SpaceItem> kvp in list)
                {
                    SpaceItem s = kvp.Value;
                    if (s != moving_item)
                    {
                        double dist = Helper.VectorLength(Helper.VectorSubtract(s.position, moving_item.position));
                        Tuple <double, double, double> direction = Helper.VectorNormalize(Helper.VectorSubtract(s.position, moving_item.position));
                        Tuple <double, double, double> force     = Helper.VectorMultiply(direction, GravConst * ((moving_item.mass * s.mass) / (dist * dist)));
                        Tuple <double, double, double> acc       = Helper.VectorDivide(force, moving_item.mass);
                        velocity = Helper.VectorAdd(velocity, Helper.VectorMultiply(acc, 0.01666666));
                    }
                }

                position = Helper.VectorAdd(position, Helper.VectorMultiply(velocity, 0.01666666));
                positions.Add(position);
            }



            return(positions);
        }
Beispiel #2
0
        private void PrintDebug()
        {
            string debugStr = "";

            foreach (KeyValuePair <string, SpaceItem> kvp in spaceitems)
            {
                SpaceItem s = kvp.Value;
                debugStr += s.name + "\n";
                debugStr += "  Lx: " + s.position.Item1.ToString() + "\n";
                debugStr += "  Ly: " + s.position.Item2.ToString() + "\n";
                debugStr += "  Lz: " + s.position.Item3.ToString() + "\n";
                debugStr += "  Vx: " + s.velocity.Item1.ToString() + "\n";
                debugStr += "  Vy: " + s.velocity.Item2.ToString() + "\n";
                debugStr += "  Vz: " + s.velocity.Item3.ToString() + "\n";
                debugStr += "  Vt: " + Helper.VectorLength(s.velocity).ToString() + "\n";
                debugStr += "\n";
                debugStr += "  SL: " + (s.position.Item1 * preview.scale).ToString() + "\n";
                debugStr += "  Pc: " + s.orbitPoints.Count.ToString() + "\n";
                //debugStr += "  Rx: " + s.stateVectorR.Item1.ToString() + "\n";
                //debugStr += "  Ry: " + s.stateVectorR.Item2.ToString() + "\n";
                //debugStr += "  Rz: " + s.stateVectorR.Item3.ToString() + "\n";
                //debugStr += "  Tx: " + s.thrust.Item1.ToString() + "\n";
                //debugStr += "  Ty: " + s.thrust.Item2.ToString() + "\n";
                //debugStr += "  Tz: " + s.thrust.Item3.ToString() + "\n";

                /**debugStr += " gee: " + Math.Round(s.gee, 3).ToString() + "\n";
                 * debugStr += " sma: " + s.sma.ToString() + "\n";
                 * debugStr += "   p: " + s.p.ToString() + "\n";
                 * debugStr += "   i: " + s.i.ToString() + "\n";
                 * debugStr += "   O: " + s.omega.ToString() + "\n";
                 * debugStr += "argp: " + s.argp.ToString() + "\n";
                 * debugStr += "  nu: " + s.nu.ToString() + "\n";
                 * debugStr += " nu°: " + Helper.rad2deg(s.nu).ToString() + "\n";
                 * debugStr += "   e: " + s.e.ToString() + "\n";
                 * debugStr += "   d: " + Helper.DensityAtAltitude(s.altitude).ToString() + "\n";
                 * debugStr += " Per: " + Math.Round(s.Periapse).ToString() + "\n";
                 * debugStr += " Apo: " + Math.Round(s.Apoapse).ToString() + "\n";
                 * debugStr += " Hgt: " + Math.Round(s.altitude).ToString() + "\n";
                 * debugStr += "ApoX: " + Math.Round(s.aMin).ToString() + " - " + Math.Round(s.aMax).ToString() + "\n";
                 * debugStr += "PerX: " + Math.Round(s.pMin).ToString() + " - " + Math.Round(s.pMax).ToString() + "\n";
                 * debugStr += "AltX: " + Math.Round(s.hMin).ToString() + " - " + Math.Round(s.hMax).ToString() + "\n";
                 * /**/
            }

            debugStr  += "\n";
            debugStr  += "Scale: " + preview.GetScale().ToString() + "\n";
            debug.Text = debugStr;
        }
Beispiel #3
0
 public virtual void updateVelocity(double deltaTime, Dictionary <string, SpaceItem> items)
 {
     foreach (KeyValuePair <string, SpaceItem> kvp in items)
     {
         SpaceItem s = kvp.Value;
         if (s != this)
         {
             double dist = Helper.VectorLength(Helper.VectorSubtract(s.position, this.position));
             Tuple <double, double, double> direction = Helper.VectorNormalize(Helper.VectorSubtract(s.position, this.position));
             Tuple <double, double, double> force     = Helper.VectorMultiply(direction, GravConst * ((this.mass * s.mass) / (dist * dist)));
             Tuple <double, double, double> acc       = Helper.VectorDivide(force, this.mass);
             // deltatime is in milliseconds
             velocity = Helper.VectorAdd(velocity, Helper.VectorMultiply(acc, deltaTime / 1000.0));
         }
     }
 }
Beispiel #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;


            // DRAW SPACEITEMS
            foreach (KeyValuePair <string, SpaceItem> kvp in list)
            {
                SpaceItem s    = kvp.Value;
                float     cX   = (float)((this.Width / 2f) + (s.position.Item1 * scale) - (s.radius * scale) + (offsetX * scale));
                float     cY   = (float)((this.Height / 2f) - (s.position.Item2 * scale) - (s.radius * scale) + (offsetY * scale));
                float     size = (float)(2 * (s.radius * scale));
                g.FillEllipse(center, cX, cY, size, size);

                if (s.type == SpaceItem.SpaceItemType.SPACECRAFT || s.type == SpaceItem.SpaceItemType.MOON)
                {
                    List <Tuple <double, double, double> > future = OrbitHelper.IteratePosition(s, list, iterations);
                    for (int i = 0; i < future.Count - 1; i++)
                    {
                        g.DrawLine(orbitPen,
                                   (float)((this.Width / 2f) + (future[i].Item1 * scale)),
                                   (float)((this.Height / 2f) + (future[i].Item2 * -scale)),
                                   (float)((this.Width / 2f) + (future[i + 1].Item1 * scale)),
                                   (float)((this.Height / 2f) + (future[i + 1].Item2 * -scale))
                                   );
                    }

                    List <Tuple <double, double, double> > points = s.orbitPoints.ToList();
                    PointF[] pointsXY = new PointF[points.Count];
                    for (int i = 0; i < points.Count; i++)
                    {
                        pointsXY[i] = new PointF(
                            (float)((this.Width / 2f) + (points[i].Item1 * scale) + (offsetX * scale)),
                            (float)((this.Height / 2f) + (points[i].Item2 * -scale) + (offsetY * scale))
                            );
                    }
                    if (pointsXY.Count() >= 2)
                    {
                        g.DrawLines(orbitPenG, pointsXY);
                    }
                }
            }

            // DRAW EARTH
            //g.FillEllipse(center, (float)((this.Width / 2f) - (earthRadius * scale)), (float)((this.Height / 2f) - (earthRadius * scale)), (float)(2 * (earthRadius * scale)), (float)(2 * (earthRadius * scale)));

            // DRAW PAST POSITIONS

            /**
             * if(orbitPointsXY.Count > 1)
             * {
             *      for(int i = 0; i < orbitPointsXY.Count - 1; i++)
             *      {
             *              g.DrawLine(orbitPen,
             *                      (float)((this.Width / 2f) + (orbitPointsXY[i].Item1 * scale)),
             *                      (float)((this.Height / 2f) + (orbitPointsXY[i].Item2 * -scale)),
             *                      (float)((this.Width / 2f) + (orbitPointsXY[i+1].Item1 * scale)),
             *                      (float)((this.Height / 2f) + (orbitPointsXY[i+1].Item2 * -scale))
             *                      );
             *      }
             * }**/


            // DRAW SPACECRAFT-DOTS
            foreach (KeyValuePair <string, SpaceItem> kvp in list)
            {
                SpaceItem s = kvp.Value;
                if (s.type == SpaceItem.SpaceItemType.SPACECRAFT)
                {
                    float size = 2f;
                    float cX   = (float)((this.Width / 2f) + (s.position.Item1 * scale) - (size / 2f) + (offsetX * scale));
                    float cY   = (float)((this.Height / 2f) - (s.position.Item2 * scale) - (size / 2f) + (offsetY * scale));

                    g.FillEllipse(craft, cX, cY, size, size);
                }
            }
        }