Example #1
0
        public override bool GetData(Object d)
        {
            EDDiscoveryForm _discoveryForm = (EDDiscoveryForm)d;

            if (_discoveryForm.RouteControl.RouteSystems == null ||
                _discoveryForm.RouteControl.RouteSystems.Count == 0)
            {
                ExtendedControls.MessageBoxTheme.Show(String.Format("Please create a route on the route tab"), TITLE);
                return(false);
            }

            Point3D last = null;

            foreach (SystemClassDB s in _discoveryForm.RouteControl.RouteSystems)
            {
                Point3D pos  = new Point3D(s.x, s.y, s.z);
                double  dist = 0;
                if (last != null)
                {
                    dist = Point3D.DistanceBetween(pos, last);
                }
                last = pos;
                data.Add(new KeyValuePair <String, double>(s.name, dist));
            }
            return(true);
        }
Example #2
0
        private RoutePlotter CreateRoutePlotter()
        {
            RoutePlotter p            = new RoutePlotter();
            string       maxrangetext = textBox_Range.Text;

            if (!float.TryParse(maxrangetext, out p.maxrange))
            {
                p.maxrange = 30;
            }
            p.usingcoordsfrom = textBox_From.ReadOnly == true;
            p.usingcoordsto   = textBox_To.ReadOnly == true;
            GetCoordsFrom(out p.coordsfrom);                      // will be valid for a system or a co-ords box
            GetCoordsTo(out p.coordsto);
            p.fromsys     = textBox_From.Text;
            p.tosys       = textBox_To.Text;
            p.routemethod = comboBoxRoutingMetric.SelectedIndex;

            if (p.usingcoordsfrom)
            {
                p.fromsys = "START POINT";
            }
            if (p.usingcoordsto)
            {
                p.tosys = "END POINT";
            }

            p.possiblejumps = (int)(Point3D.DistanceBetween(p.coordsfrom, p.coordsto) / p.maxrange);

            return(p);
        }
Example #3
0
        private void UpdateTo(bool updatename)
        {
            changesilence = true;

            if (textBox_To.ReadOnly == false)                // if entering system name..
            {
                ISystem ds1 = discoveryform.history.FindSystem(SystemNameOnly(textBox_To.Text), discoveryform.galacticMapping);

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        if (ds1 is GalacticMapSystem)
                        {
                            GalacticMapSystem gms = (GalacticMapSystem)ds1;
                            textBox_To.Text = gms.GalMapObject.name;
                        }
                        else
                        {
                            textBox_To.Text = ds1.Name;
                        }
                    }

                    textBox_ToName.Text = ds1.Name;
                    textBox_ToX.Text = ds1.X.ToString("0.00");
                    textBox_ToY.Text = ds1.Y.ToString("0.00");
                    textBox_ToZ.Text = ds1.Z.ToString("0.00");
                }
                else
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
            }
            else // Co-ords..
            {
                string res = "";
                Point3D curpos;
                if (GetCoordsTo(out curpos))
                {
                    ISystem nearest = SystemClassDB.FindNearestSystemTo(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.X, nearest.Y, nearest.Z));
                        if (distance < 0.1)
                            res = nearest.Name;
                        else
                            res = nearest.Name + " @ " + distance.ToString("0.00") + "ly";
                    }
                }

                textBox_To.Text = res;
                textBox_ToName.Text = res;
            }

            UpdateDistance();

            changesilence = false;
            button_Route.Enabled = IsValid();
        }
Example #4
0
        private void RouteMain()
        {
            float   maxrange        = 30;
            bool    usingcoordsfrom = false;
            bool    usingcoordsto   = false;
            Point3D coordsfrom      = new Point3D(0, 0, 0);
            Point3D coordsto        = new Point3D(0, 0, 0);
            string  fromsys         = "";
            string  tosys           = "";
            int     routemethod     = 0;

            Invoke((MethodInvoker) delegate {                       // we are in a thread, should pick info up using a delegate
                maxrange        = float.Parse(textBox_Range.Text);
                usingcoordsfrom = textBox_From.ReadOnly == true;
                usingcoordsto   = textBox_To.ReadOnly == true;
                GetCoordsFrom(out coordsfrom);                      // will be valid for a system or a co-ords box
                GetCoordsTo(out coordsto);
                fromsys     = textBox_From.Text;
                tosys       = textBox_To.Text;
                routemethod = comboBoxRoutingMetric.SelectedIndex;
            });

            if (usingcoordsfrom)
            {
                fromsys = "START POINT";
            }
            if (usingcoordsto)
            {
                tosys = "END POINT";
            }

            double possiblejumps = Point3D.DistanceBetween(coordsfrom, coordsto) / maxrange;

            if (possiblejumps > 100)
            {
                DialogResult res = MessageBox.Show("This will result in a large number (" + possiblejumps.ToString("0") + ") of jumps" + Environment.NewLine + Environment.NewLine + "Confirm please", "Confirm you want to compute", MessageBoxButtons.YesNo);
                if (res != System.Windows.Forms.DialogResult.Yes)
                {
                    this.Invoke(new Action(() => button_Route.Enabled = true));
                    return;
                }
            }

            if (routemethod == metric_astar)       // AStar method
            {
                Route(fromsys, usingcoordsfrom, coordsfrom,
                      tosys, usingcoordsto, coordsto,
                      maxrange);
            }
            else
            {
                RouteIterative(fromsys, usingcoordsfrom, coordsfrom,
                               tosys, usingcoordsto, coordsto,
                               maxrange, routemethod);
            }

            this.Invoke(new Action(() => button_Route.Enabled = true));
        }
Example #5
0
        private void UpdateDistance()
        {
            Point3D from, to;
            string dist = "";
            if (GetCoordsFrom(out from) && GetCoordsTo(out to))
            {
                dist = Point3D.DistanceBetween(from, to).ToString("0.00");
            }

            textBox_Distance.Text = dist;
        }
Example #6
0
        private void UpdateTo(bool updatename)
        {
            changesilence = true;

            if (textBox_To.ReadOnly == false)                // if entering system name..
            {
                EDDiscovery2.DB.ISystem ds1 = SystemClass.GetSystem(SystemNameOnly(textBox_To.Text));

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        textBox_To.Text = ds1.name;
                    }

                    textBox_ToX.Text = ds1.x.ToString("0.00");
                    textBox_ToY.Text = ds1.y.ToString("0.00");
                    textBox_ToZ.Text = ds1.z.ToString("0.00");
                }
                else
                {
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
                }
            }
            else // Co-ords..
            {
                string  res = "";
                Point3D curpos;
                if (GetCoordsTo(out curpos))
                {
                    ISystem nearest = SystemClass.FindNearestSystem(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.x, nearest.y, nearest.z));
                        if (distance < 0.1)
                        {
                            res = nearest.name;
                        }
                        else
                        {
                            res = nearest.name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_To.Text = res;
            }

            UpdateDistance();

            changesilence        = false;
            button_Route.Enabled = IsValid();
        }
Example #7
0
        private void button_Route_Click(object sender, EventArgs e)
        {
            if (routingthread == null || !routingthread.IsAlive)
            {
                plotter          = new RoutePlotter();
                plotter.MaxRange = textBox_Range.Value;
                GetCoordsFrom(out plotter.Coordsfrom);                      // will be valid for a system or a co-ords box
                GetCoordsTo(out plotter.Coordsto);
                plotter.FromSystem  = textBox_From.Text;
                plotter.ToSystem    = textBox_To.Text;
                plotter.RouteMethod = (SystemsDB.SystemsNearestMetric)comboBoxRoutingMetric.SelectedIndex;
                plotter.UseFsdBoost = checkBox_FsdBoost.Checked;

                if (textBox_From.ReadOnly == true)
                {
                    plotter.FromSystem = "START POINT";
                }
                if (textBox_To.ReadOnly == true)
                {
                    plotter.ToSystem = "END POINT";
                }

                int PossibleJumps = (int)(Point3D.DistanceBetween(plotter.Coordsfrom, plotter.Coordsto) / plotter.MaxRange);

                if (PossibleJumps > 100)
                {
                    DialogResult res = ExtendedControls.MessageBoxTheme.Show(FindForm(),
                                                                             string.Format(("This will result in a large number ({0}) of jumps" + Environment.NewLine + "Confirm please").T(EDTx.UserControlRoute_Confirm),
                                                                                           PossibleJumps), "Warning".T(EDTx.Warning), MessageBoxButtons.YesNo);
                    if (res != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }
                }

                dataGridViewRoute.Rows.Clear();
                routingthread      = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RoutingThread));
                routingthread.Name = "Thread Route";

                cmd3DMap.Enabled  = false;
                button_Route.Text = "Cancel".T(EDTx.Cancel);
                routingthread.Start(plotter);
            }
            else
            {
                plotter.StopPlotter  = true;
                button_Route.Enabled = false;
            }
        }
Example #8
0
        private void button_Route_Click(object sender, EventArgs e)
        {
            ToggleButtons(false);           // beware the tab order, this moves the focus onto the next control, which in this dialog can be not what we want.

            plotter          = new RoutePlotter();
            plotter.MaxRange = textBox_Range.Value;
            GetCoordsFrom(out plotter.Coordsfrom);                      // will be valid for a system or a co-ords box
            GetCoordsTo(out plotter.Coordsto);
            plotter.FromSystem  = textBox_From.Text;
            plotter.ToSystem    = textBox_To.Text;
            plotter.RouteMethod = comboBoxRoutingMetric.SelectedIndex;

            if (textBox_From.ReadOnly == true)
            {
                plotter.FromSystem = "START POINT";
            }
            if (textBox_To.ReadOnly == true)
            {
                plotter.ToSystem = "END POINT";
            }

            int PossibleJumps = (int)(Point3D.DistanceBetween(plotter.Coordsfrom, plotter.Coordsto) / plotter.MaxRange);

            if (PossibleJumps > 100)
            {
                DialogResult res = ExtendedControls.MessageBoxTheme.Show(FindForm(),
                                                                         string.Format(("This will result in a large number ({0}) of jumps" + Environment.NewLine + "Confirm please").Tx(this, "Confirm"),
                                                                                       PossibleJumps), "Warning".Tx(), MessageBoxButtons.YesNo);
                if (res != System.Windows.Forms.DialogResult.Yes)
                {
                    ToggleButtons(true);
                    return;
                }
            }

            dataGridViewRoute.Rows.Clear();
            routingthread      = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(RoutingThread));
            routingthread.Name = "Thread Route";
            routingthread.Start(plotter);
        }
Example #9
0
        /// <summary>
        /// This function will find the closest node from a geographical position in space.
        /// </summary>
        /// <param name="PtX">X coordinate of the point from which you want the closest node.</param>
        /// <param name="PtY">Y coordinate of the point from which you want the closest node.</param>
        /// <param name="PtZ">Z coordinate of the point from which you want the closest node.</param>
        /// <param name="Distance">The distance to the closest node.</param>
        /// <param name="IgnorePassableProperty">if 'false', then nodes whose property Passable is set to false will not be taken into account.</param>
        /// <returns>The closest node that has been found.</returns>
        public Node ClosestNode(double PtX, double PtY, double PtZ, out double Distance, bool IgnorePassableProperty)
        {
            Node    NodeMin     = null;
            double  DistanceMin = -1;
            Point3D P           = new Point3D(PtX, PtY, PtZ);

            foreach (Node N in LN)
            {
                if (IgnorePassableProperty && N.Passable == false)
                {
                    continue;
                }
                double DistanceTemp = Point3D.DistanceBetween(N.Position, P);
                if (DistanceMin == -1 || DistanceMin > DistanceTemp)
                {
                    DistanceMin = DistanceTemp;
                    NodeMin     = N;
                }
            }
            Distance = DistanceMin;
            return(NodeMin);
        }
Example #10
0
        private void FindNearestSystem(Point3D curpos, out SystemClass system, out double distance)
        {
            List <SystemClass> systems       = SystemData.SystemList;
            SystemClass        nearestsystem = null;
            double             mindistance   = 1E19;

            for (int ii = 0; ii < systems.Count; ii++)
            {
                SystemClass syscheck    = systems[ii];
                Point3D     syspos      = new Point3D(syscheck.x, syscheck.y, syscheck.z);
                double      curdistance = Point3D.DistanceBetween(curpos, syspos);

                if (curdistance < mindistance)
                {
                    nearestsystem = syscheck;
                    mindistance   = curdistance;
                }
            }

            system   = nearestsystem;
            distance = mindistance;
        }
Example #11
0
        /// <summary>
        /// This function will find the closest arc from a geographical position in space using projection.
        /// </summary>
        /// <param name="PtX">X coordinate of the point from which you want the closest arc.</param>
        /// <param name="PtY">Y coordinate of the point from which you want the closest arc.</param>
        /// <param name="PtZ">Z coordinate of the point from which you want the closest arc.</param>
        /// <param name="Distance">The distance to the closest arc.</param>
        /// <param name="IgnorePassableProperty">if 'false', then arcs whose property Passable is set to false will not be taken into account.</param>
        /// <returns>The closest arc that has been found.</returns>
        public Arc ClosestArc(double PtX, double PtY, double PtZ, out double Distance, bool IgnorePassableProperty)
        {
            Arc     ArcMin      = null;
            double  DistanceMin = -1;
            Point3D P           = new Point3D(PtX, PtY, PtZ);

            foreach (Arc A in LA)
            {
                if (IgnorePassableProperty && A.Passable == false)
                {
                    continue;
                }
                Point3D Projection   = Point3D.ProjectOnLine(P, A.StartNode.Position, A.EndNode.Position);
                double  DistanceTemp = Point3D.DistanceBetween(P, Projection);
                if (DistanceMin == -1 || DistanceMin > DistanceTemp)
                {
                    DistanceMin = DistanceTemp;
                    ArcMin      = A;
                }
            }
            Distance = DistanceMin;
            return(ArcMin);
        }
        private void UpdateTotalDistances()
        {
            double distance = 0;

            txtCmlDistance.Text = distance.ToString("0.00") + "LY";
            txtP2PDIstance.Text = distance.ToString("0.00") + "LY";
            if (dataGridViewRouteSystems.Rows.Count > 1)
            {
                SystemClass firstSC = null;
                SystemClass lastSC  = null;
                for (int i = 0; i < dataGridViewRouteSystems.Rows.Count; i++)
                {
                    if (firstSC == null && dataGridViewRouteSystems[0, i].Tag != null)
                    {
                        firstSC = (SystemClass)dataGridViewRouteSystems[0, i].Tag;
                    }
                    if (dataGridViewRouteSystems[0, i].Tag != null)
                    {
                        lastSC = (SystemClass)dataGridViewRouteSystems[0, i].Tag;
                    }
                    String value = dataGridViewRouteSystems[1, i].Value as string;
                    if (!String.IsNullOrWhiteSpace(value))
                    {
                        distance += Double.Parse(value);
                    }
                }
                txtCmlDistance.Text = distance.ToString("0.00") + "LY";
                distance            = 0;
                if (firstSC != null && lastSC != null)
                {
                    Point3D first = new Point3D(firstSC.x, firstSC.y, firstSC.z);
                    Point3D last  = new Point3D(lastSC.x, lastSC.y, lastSC.z);
                    distance            = Point3D.DistanceBetween(first, last);
                    txtP2PDIstance.Text = distance.ToString("0.00") + "LY";
                }
            }
        }
        public List <ISystem> RouteIterative(Action <ReturnInfo> info)
        {
            double         traveldistance = Point3D.DistanceBetween(Coordsfrom, Coordsto); // its based on a percentage of the traveldistance
            List <ISystem> routeSystems   = new List <ISystem>();

            System.Diagnostics.Debug.WriteLine("From " + FromSystem + " to  " + ToSystem + ", using metric " + RouteMethod.ToString());

            routeSystems.Add(new SystemClass(FromSystem, Coordsfrom.X, Coordsfrom.Y, Coordsfrom.Z));

            info(new ReturnInfo(FromSystem, double.NaN, Coordsfrom, double.NaN, double.NaN, routeSystems[0]));

            Point3D curpos         = Coordsfrom;
            int     jump           = 1;
            double  actualdistance = 0;

            float maxfromwanted = (MaxRange < 100) ? (MaxRange - 1) : (100 + MaxRange * 1 / 5);       // if <100, then just make sure we jump off by 1 yr, else its a 100+1/5

            maxfromwanted = Math.Min(maxfromwanted, MaxRange - 1);

            do
            {
                double distancetogo = Point3D.DistanceBetween(Coordsto, curpos);      // to go

                if (distancetogo <= MaxRange)                                         // within distance, we can go directly
                {
                    break;
                }

                Point3D travelvector      = new Point3D(Coordsto.X - curpos.X, Coordsto.Y - curpos.Y, Coordsto.Z - curpos.Z);                         // vector to destination
                Point3D travelvectorperly = new Point3D(travelvector.X / distancetogo, travelvector.Y / distancetogo, travelvector.Z / distancetogo); // per ly travel vector

                Point3D expectedNextPosition = GetNextPosition(curpos, travelvectorperly, MaxRange);                                                  // where we would like to be..
                ISystem bestsystem           = GetBestJumpSystem(curpos, travelvectorperly, maxfromwanted, MaxRange);                                 // see if we can find a system near  our target

                // if we haven't found a system in range, let's try boosting
                int boostStrength = 0;
                while (UseFsdBoost && bestsystem == null && boostStrength < 4)
                {
                    boostStrength = 1 << boostStrength;
                    float   maxRangeWithBoost   = MaxRange * (1.0f + BoostPercentage(boostStrength));
                    ISystem bestSystemWithBoost = GetBestJumpSystem(curpos, travelvectorperly, maxfromwanted, maxRangeWithBoost);

                    if (bestSystemWithBoost != null)
                    {
                        bestsystem = bestSystemWithBoost;
                    }
                }

                Point3D nextpos           = expectedNextPosition; // where we really are going to be
                string  sysname           = "WAYPOINT";
                double  deltafromwaypoint = 0;
                double  deviation         = 0;

                if (bestsystem != null)
                {
                    nextpos           = new Point3D(bestsystem.X, bestsystem.Y, bestsystem.Z);
                    deltafromwaypoint = Point3D.DistanceBetween(nextpos, expectedNextPosition);     // how much in error
                    deviation         = Point3D.DistanceBetween(curpos.InterceptPoint(expectedNextPosition, nextpos), nextpos);
                    sysname           = bestsystem.Name;
                    if (boostStrength > 0)
                    {
                        sysname += " (+" + BoostPercentage(boostStrength) * 100 + "% Boost)";
                    }
                    routeSystems.Add(bestsystem);
                }

                info(new ReturnInfo(sysname, Point3D.DistanceBetween(curpos, nextpos), nextpos, deltafromwaypoint, deviation, bestsystem));

                actualdistance += Point3D.DistanceBetween(curpos, nextpos);
                curpos          = nextpos;
                jump++;
            } while (!StopPlotter);

            routeSystems.Add(new SystemClass(ToSystem, Coordsto.X, Coordsto.Y, Coordsto.Z));

            actualdistance += Point3D.DistanceBetween(curpos, Coordsto);

            info(new ReturnInfo(ToSystem, Point3D.DistanceBetween(curpos, Coordsto), Coordsto, double.NaN, double.NaN, routeSystems.Last()));

            info(new ReturnInfo("Straight Line Distance", traveldistance));
            info(new ReturnInfo("Travelled Distance", actualdistance));

            return(routeSystems);
        }
Example #14
0
        public List <ISystem> RouteIterative(Action <ReturnInfo> info)
        {
            double         traveldistance = Point3D.DistanceBetween(coordsfrom, coordsto); // its based on a percentage of the traveldistance
            List <ISystem> routeSystems   = new List <ISystem>();

            System.Diagnostics.Debug.WriteLine("From " + fromsys + " to  " + tosys);

            routeSystems.Add(new SystemClass(fromsys, coordsfrom.X, coordsfrom.Y, coordsfrom.Z));

            info(new ReturnInfo(fromsys, double.NaN, coordsfrom, double.NaN, double.NaN, routeSystems[0]));

            Point3D curpos         = coordsfrom;
            int     jump           = 1;
            double  actualdistance = 0;

            do
            {
                double distancetogo = Point3D.DistanceBetween(coordsto, curpos);      // to go

                if (distancetogo <= maxrange)                                         // within distance, we can go directly
                {
                    break;
                }

                Point3D travelvector      = new Point3D(coordsto.X - curpos.X, coordsto.Y - curpos.Y, coordsto.Z - curpos.Z);                         // vector to destination
                Point3D travelvectorperly = new Point3D(travelvector.X / distancetogo, travelvector.Y / distancetogo, travelvector.Z / distancetogo); // per ly travel vector

                Point3D nextpos = new Point3D(curpos.X + maxrange * travelvectorperly.X,
                                              curpos.Y + maxrange * travelvectorperly.Y,
                                              curpos.Z + maxrange * travelvectorperly.Z);   // where we would like to be..

                ISystem bestsystem = DB.SystemClassDB.GetSystemNearestTo(curpos, nextpos, maxrange, maxrange - 0.5, routemethod);

                string sysname           = "WAYPOINT";
                double deltafromwaypoint = 0;
                double deviation         = 0;

                if (bestsystem != null)
                {
                    Point3D bestposition = new Point3D(bestsystem.x, bestsystem.y, bestsystem.z);
                    deltafromwaypoint = Point3D.DistanceBetween(bestposition, nextpos);     // how much in error
                    deviation         = Point3D.DistanceBetween(curpos.InterceptPoint(nextpos, bestposition), bestposition);
                    nextpos           = bestposition;
                    sysname           = bestsystem.name;
                    routeSystems.Add(bestsystem);
                }

                info(new ReturnInfo(sysname, Point3D.DistanceBetween(curpos, nextpos), nextpos, deltafromwaypoint, deviation, bestsystem));

                actualdistance += Point3D.DistanceBetween(curpos, nextpos);
                curpos          = nextpos;
                jump++;
            } while (true);

            routeSystems.Add(new SystemClass(tosys, coordsto.X, coordsto.Y, coordsto.Z));

            actualdistance += Point3D.DistanceBetween(curpos, coordsto);

            info(new ReturnInfo(tosys, Point3D.DistanceBetween(curpos, coordsto), coordsto, double.NaN, double.NaN, routeSystems.Last()));

            info(new ReturnInfo("Straight Line Distance", traveldistance));
            info(new ReturnInfo("Travelled Distance", actualdistance));

            return(routeSystems);
        }
        internal static ISystem GetSystemNearestTo(Point3D currentpos,
                                                   Point3D wantedpos,
                                                   double maxfromcurpos,
                                                   double maxfromwanted,
                                                   int routemethod,
                                                   SQLiteConnectionSystem cn,
                                                   Action <ISystem> LookedUp = null,
                                                   int limitto = 1000)
        {
            using (DbCommand cmd = cn.CreateSelect("Systems s",
                                                   MakeSystemQueryEDDB,
                                                   where :
                                                   "x >= @xc - @maxfromcurpos " +
                                                   "AND x <= @xc + @maxfromcurpos " +
                                                   "AND z >= @zc - @maxfromcurpos " +
                                                   "AND z <= @zc + @maxfromcurpos " +
                                                   "AND x >= @xw - @maxfromwanted " +
                                                   "AND x <= @xw + @maxfromwanted " +
                                                   "AND z >= @zw - @maxfromwanted " +
                                                   "AND z <= @zw + @maxfromwanted " +
                                                   "AND y >= @yc - @maxfromcurpos " +
                                                   "AND y <= @yc + @maxfromcurpos " +
                                                   "AND y >= @yw - @maxfromwanted " +
                                                   "AND y <= @yw + @maxfromwanted ",
                                                   orderby: "(s.x-@xw)*(s.x-@xw)+(s.y-@yw)*(s.y-@yw)+(s.z-@zw)*(s.z-@zw)", // orderby distance from wanted
                                                   limit: limitto,
                                                   joinlist: MakeSystemQueryEDDBJoinList))
            {
                cmd.AddParameterWithValue("@xw", SystemClass.DoubleToInt(wantedpos.X));         // easier to manage with named paras
                cmd.AddParameterWithValue("@yw", SystemClass.DoubleToInt(wantedpos.Y));
                cmd.AddParameterWithValue("@zw", SystemClass.DoubleToInt(wantedpos.Z));
                cmd.AddParameterWithValue("@maxfromwanted", SystemClass.DoubleToInt(maxfromwanted));
                cmd.AddParameterWithValue("@xc", SystemClass.DoubleToInt(currentpos.X));
                cmd.AddParameterWithValue("@yc", SystemClass.DoubleToInt(currentpos.Y));
                cmd.AddParameterWithValue("@zc", SystemClass.DoubleToInt(currentpos.Z));
                cmd.AddParameterWithValue("@maxfromcurpos", SystemClass.DoubleToInt(maxfromcurpos));

                //System.Diagnostics.Debug.WriteLine(cn.ExplainQueryPlanString(cmd));

                double      bestmindistance = double.MaxValue;
                SystemClass nearestsystem   = null;

                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        SystemClass s = MakeSystem(reader);
                        LookedUp?.Invoke(s);                            // callback to say looked up

                        Point3D syspos = new Point3D(s.X, s.Y, s.Z);
                        double  distancefromwantedx2 = Point3D.DistanceBetweenX2(wantedpos, syspos);  // range between the wanted point and this, ^2
                        double  distancefromcurposx2 = Point3D.DistanceBetweenX2(currentpos, syspos); // range between the wanted point and this, ^2

                        // ENSURE its withing the circles now
                        if (distancefromcurposx2 <= (maxfromcurpos * maxfromcurpos) && distancefromwantedx2 <= (maxfromwanted * maxfromwanted))
                        {
                            if (routemethod == metric_nearestwaypoint)
                            {
                                if (distancefromwantedx2 < bestmindistance)
                                {
                                    nearestsystem   = s;
                                    bestmindistance = distancefromwantedx2;
                                }
                            }
                            else
                            {
                                Point3D interceptpoint = currentpos.InterceptPoint(wantedpos, syspos);      // work out where the perp. intercept point is..
                                double  deviation      = Point3D.DistanceBetween(interceptpoint, syspos);
                                double  metric         = 1E39;

                                if (routemethod == metric_mindevfrompath)
                                {
                                    metric = deviation;
                                }
                                else if (routemethod == metric_maximum100ly)
                                {
                                    metric = (deviation <= 100) ? distancefromwantedx2 : metric;        // no need to sqrt it..
                                }
                                else if (routemethod == metric_maximum250ly)
                                {
                                    metric = (deviation <= 250) ? distancefromwantedx2 : metric;
                                }
                                else if (routemethod == metric_maximum500ly)
                                {
                                    metric = (deviation <= 500) ? distancefromwantedx2 : metric;
                                }
                                else if (routemethod == metric_waypointdev2)
                                {
                                    metric = Math.Sqrt(distancefromwantedx2) + deviation / 2;
                                }

                                if (metric < bestmindistance)
                                {
                                    nearestsystem   = s;
                                    bestmindistance = metric;
                                }
                            }
                        }
                    }
                }

                return(nearestsystem);
            }
        }
Example #16
0
        // AStar method, for large jumps with large max ranges, or over long distances, it gets bogged down.

        private void Route(string fromsys, bool usingcoordsfrom, Point3D coordsfrom,
                           string tosys, bool usingcoordsto, Point3D coordsto,
                           float maxrange)
        {
            double xwindow          = Math.Abs(coordsfrom.X - coordsto.X);              // we need a window of co-ords
            double ywindow          = Math.Abs(coordsfrom.Y - coordsto.Y);              // to pick up systems. consider from 0,0,0 to 0,1000,1000
            double zwindow          = Math.Abs(coordsfrom.Z - coordsto.Z);              // x has no window.
            double traveldistance   = Point3D.DistanceBetween(coordsfrom, coordsto);    // its based on a percentage of the traveldistance
            double wanderpercentage = 0.1;
            double wanderwindow     = traveldistance * wanderpercentage;                // this is the minimum window size

            if (maxrange > 50)
            {
                DialogResult res1 = MessageBox.Show("Using a large range will result in a great number of possible paths and the computation may take a very long time" + Environment.NewLine + Environment.NewLine + "Confirm please", "Confirm you want to compute", MessageBoxButtons.YesNo);
                if (res1 != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }
            }

            if (wanderwindow > 100)                                                     // limit, otherwise we just get too many
            {
                wanderwindow = 100;
            }

            xwindow = (xwindow < wanderwindow) ? (wanderwindow / 2) : 10;               // if less than the wander window, open it up, else open it up a little so it can
            ywindow = (ywindow < wanderwindow) ? (wanderwindow / 2) : 10;               // find start/end points without any rounding errors..
            zwindow = (zwindow < wanderwindow) ? (wanderwindow / 2) : 10;

            Point3D minpos = new EMK.LightGeometry.Point3D(
                Math.Min(coordsfrom.X, coordsto.X) - xwindow,
                Math.Min(coordsfrom.Y, coordsto.Y) - ywindow,
                Math.Min(coordsfrom.Z, coordsto.Z) - zwindow);
            Point3D maxpos = new EMK.LightGeometry.Point3D(
                Math.Max(coordsfrom.X, coordsto.X) + xwindow,
                Math.Max(coordsfrom.Y, coordsto.Y) + ywindow,
                Math.Max(coordsfrom.Z, coordsto.Z) + zwindow);

            AppendText("Bounding Box " + minpos.X.ToString("0.0") + "," + minpos.Y.ToString("0.0") + "," + minpos.Z.ToString("0.0") + " to " + maxpos.X.ToString("0.0") + "," + maxpos.Y.ToString("0.0") + "," + maxpos.Z.ToString("0.0") + " window " + wanderwindow.ToString("0.0") + Environment.NewLine);

            Stopwatch sw = new Stopwatch();

            G = new Graph();                    // need to compute each time as systems in range changes each time

            AddStarNodes(G, minpos, maxpos);

            if (usingcoordsfrom)                    // if using an arbitary point, add it as a system..
            {
                SystemClass system = new SystemClass(fromsys);
                system.x = coordsfrom.X;
                system.y = coordsfrom.Y;
                system.z = coordsfrom.Z;
                G.AddNodeWithNoChk(new Node(system.x, system.y, system.z, system));
            }

            if (usingcoordsto)                      // if using an arbitary point, add it as a system..
            {
                SystemClass system = new SystemClass(tosys);
                system.x = coordsto.X;
                system.y = coordsto.Y;
                system.z = coordsto.Z;
                G.AddNodeWithNoChk(new Node(system.x, system.y, system.z, system));
            }

            AppendText("Number of stars within bounds " + G.Count + Environment.NewLine);

            CalculateArcs(G, maxrange);

            AStar AS = new AStar(G);

            Node start, stop;

            start = G.GetNodes.FirstOrDefault(x => x.System.SearchName == fromsys.ToLower());
            stop  = G.GetNodes.FirstOrDefault(x => x.System.SearchName == tosys.ToLower());

            if (start == null || stop == null)
            {
                AppendText("Code failed - Please report failure on the ED Forums, Exploration, EDDiscovery thread");
                return;
            }

            bool res;

            sw = new Stopwatch();

            sw.Start();
            res = AS.SearchPath(start, stop);
            sw.Stop();

            AppendText("Find route Time: " + sw.Elapsed.TotalSeconds.ToString("0.000s") + Environment.NewLine);

            if (res)
            {
                AppendText(Environment.NewLine + string.Format("{0,-30}Depart Co-Ords:{1:0.00},{2:0.00},{3:0.00}" + Environment.NewLine, fromsys, start.X, start.Y, start.Z));

                double totdist = 0;
                int    jumps   = 0;

                foreach (Arc A in AS.PathByArcs)
                {
                    // have to do it manually in case using the START, WAYPOINT or END points
                    double dist = Math.Sqrt((A.StartNode.X - A.EndNode.X) * (A.StartNode.X - A.EndNode.X) +
                                            (A.StartNode.Y - A.EndNode.Y) * (A.StartNode.Y - A.EndNode.Y) +
                                            (A.StartNode.Z - A.EndNode.Z) * (A.StartNode.Z - A.EndNode.Z));
                    jumps++;

                    AppendText(string.Format("{0,-30}{1,3} Dist:{2,8:0.00}ly @ {3,9:0.00},{4,8:0.00},{5,9:0.00}" + Environment.NewLine, A.EndNode.System.name, jumps, dist, A.EndNode.System.x, A.EndNode.System.y, A.EndNode.System.z));

                    totdist += dist;

                    Console.WriteLine(A.ToString());
                }

                AppendText(string.Format(Environment.NewLine + "Straight Line Distance {0,8:0.00}ly vs Travelled Distance {1,8:0.00}ly" + Environment.NewLine, traveldistance.ToString("0.00"), totdist.ToString("0.00")));
            }
            else
            {
                AppendText(Environment.NewLine + "NO Solution found - jump distance is too small or not enough star data between systems" + Environment.NewLine);
            }
        }
Example #17
0
        private void FindBestSystem(Point3D curpos, Point3D wantedpos, double maxfromcurpos, double maxfromwanted,
                                    int routemethod,
                                    out SystemClass system, out Point3D position)
        {
            List <SystemClass> systems = SystemData.SystemList;

            double maxfromcurposx2 = maxfromcurpos * maxfromcurpos;
            double maxfromwantedx2 = maxfromwanted * maxfromwanted;

            SystemClass nearestsystem = null;

            double bestmindistance = 1E39;

            for (int ii = 0; ii < systems.Count; ii++)
            {
                SystemClass syscheck             = systems[ii];
                Point3D     syspos               = new Point3D(syscheck.x, syscheck.y, syscheck.z);
                double      distancefromwantedx2 = Point3D.DistanceBetweenX2(wantedpos, syspos); // range between the wanted point and this, ^2
                double      distancefromcurposx2 = Point3D.DistanceBetweenX2(curpos, syspos);    // range between the wanted point and this, ^2

                if (distancefromwantedx2 <= maxfromwantedx2 &&                                   // if within the radius of wanted
                    distancefromcurposx2 <= maxfromcurposx2)                                     // and within the jump range of current
                {
                    if (routemethod == metric_nearestwaypoint)
                    {
                        if (distancefromwantedx2 < bestmindistance)
                        {
                            nearestsystem   = syscheck;
                            bestmindistance = distancefromwantedx2;
                        }
                    }
                    else
                    {
                        Point3D interceptpoint = curpos.InterceptPoint(wantedpos, syspos);      // work out where the perp. intercept point is..
                        double  deviation      = Point3D.DistanceBetween(interceptpoint, syspos);
                        double  metric         = 1E39;

                        if (routemethod == metric_mindevfrompath)
                        {
                            metric = deviation;
                        }
                        else if (routemethod == metric_maximum100ly)
                        {
                            metric = (deviation <= 100) ? distancefromwantedx2 : metric;        // no need to sqrt it..
                        }
                        else if (routemethod == metric_maximum250ly)
                        {
                            metric = (deviation <= 250) ? distancefromwantedx2 : metric;
                        }
                        else if (routemethod == metric_maximum500ly)
                        {
                            metric = (deviation <= 500) ? distancefromwantedx2 : metric;
                        }
                        else
                        {
                            metric = Math.Sqrt(distancefromwantedx2) + deviation / 2;
                        }

                        if (metric < bestmindistance)
                        {
                            nearestsystem   = syscheck;
                            bestmindistance = metric;
                            //Console.WriteLine("System " + syscheck.name + " way " + deviation.ToString("0.0") + " metric " + metric.ToString("0.0") + " *");
                        }
                        else
                        {
                            //Console.WriteLine("System " + syscheck.name + " way " + deviation.ToString("0.0") + " metric " + metric.ToString("0.0"));
                        }
                    }
                }
            }

            system   = nearestsystem;
            position = null;
            if (system != null)
            {
#if DEBUG
                Console.WriteLine("Best System " + nearestsystem.name);
#endif
                position = new Point3D(system.x, system.y, system.z);
            }
        }
Example #18
0
        private void RouteIterative(string fromsys, bool usingcoordsfrom, Point3D coordsfrom,
                                    string tosys, bool usingcoordsto, Point3D coordsto,
                                    float maxrange, int routemethod)
        {
            double traveldistance = Point3D.DistanceBetween(coordsfrom, coordsto);      // its based on a percentage of the traveldistance

            AppendText("Searching route from " + fromsys + " to " + tosys + Environment.NewLine);
            AppendText("Total distance: " + traveldistance.ToString("0.00") + " in " + maxrange.ToString("0.00") + "ly jumps" + Environment.NewLine);

            AppendText(Environment.NewLine + string.Format("{0,-30}    Depart          @ {1,9:0.00},{2,8:0.00},{3,9:0.00}" + Environment.NewLine, fromsys, coordsfrom.X, coordsfrom.Y, coordsfrom.Z));

            Point3D curpos         = coordsfrom;
            int     jump           = 1;
            double  actualdistance = 0;

#if DEBUG
            Console.WriteLine("-------------------------- BEGIN");
#endif
            do
            {
                double distancetogo = Point3D.DistanceBetween(coordsto, curpos);      // to go

                if (distancetogo <= maxrange)                                         // within distance, we can go directly
                {
                    break;
                }

                Point3D travelvector      = new Point3D(coordsto.X - curpos.X, coordsto.Y - curpos.Y, coordsto.Z - curpos.Z);                         // vector to destination
                Point3D travelvectorperly = new Point3D(travelvector.X / distancetogo, travelvector.Y / distancetogo, travelvector.Z / distancetogo); // per ly travel vector

                Point3D nextpos = new Point3D(curpos.X + maxrange * travelvectorperly.X,
                                              curpos.Y + maxrange * travelvectorperly.Y,
                                              curpos.Z + maxrange * travelvectorperly.Z);   // where we would like to be..

#if DEBUG
                Console.WriteLine("Curpos " + curpos.X + "," + curpos.Y + "," + curpos.Z);
                Console.WriteLine(" next" + nextpos.X + "," + nextpos.Y + "," + nextpos.Z);
#endif
                SystemClass bestsystem;
                Point3D     bestposition;

                FindBestSystem(curpos, nextpos, maxrange, maxrange - 0.5, routemethod, out bestsystem, out bestposition);
                string sysname           = "WAYPOINT";
                double deltafromwaypoint = 0;
                double deviation         = 0;

                if (bestsystem != null)
                {
                    deltafromwaypoint = Point3D.DistanceBetween(bestposition, nextpos);     // how much in error
                    deviation         = Point3D.DistanceBetween(curpos.InterceptPoint(nextpos, bestposition), bestposition);
                    nextpos           = bestposition;
                    sysname           = bestsystem.name;
                }

                AppendText(string.Format("{0,-30}{1,3} Dist:{2,8:0.00}ly @ {3,9:0.00},{4,8:0.00},{5,9:0.00} WPd:{6,8:0.00}ly Dev:{7,8:0.00}ly" + Environment.NewLine,
                                         sysname, jump, Point3D.DistanceBetween(curpos, nextpos), nextpos.X, nextpos.Y, nextpos.Z, deltafromwaypoint, deviation));

                actualdistance += Point3D.DistanceBetween(curpos, nextpos);
                curpos          = nextpos;
                jump++;
            } while (true);

            actualdistance += Point3D.DistanceBetween(curpos, coordsto);
            AppendText(string.Format("{0,-30}{1,3} Dist:{2,8:0.00}ly @ {3,9:0.00},{4,8:0.00},{5,9:0.00}" + Environment.NewLine, tosys, jump, Point3D.DistanceBetween(curpos, coordsto), coordsto.X, coordsto.Y, coordsto.Z));
            AppendText(string.Format(Environment.NewLine + "Straight Line Distance {0,8:0.00}ly vs Travelled Distance {1,8:0.00}ly" + Environment.NewLine, traveldistance, actualdistance));
        }
Example #19
0
        public List <ISystem> RouteIterative(Action <ReturnInfo> info)
        {
            double         traveldistance = Point3D.DistanceBetween(Coordsfrom, Coordsto); // its based on a percentage of the traveldistance
            List <ISystem> routeSystems   = new List <ISystem>();

            System.Diagnostics.Debug.WriteLine("From " + FromSystem + " to  " + ToSystem);

            routeSystems.Add(new SystemClass(FromSystem, Coordsfrom.X, Coordsfrom.Y, Coordsfrom.Z));

            info(new ReturnInfo(FromSystem, double.NaN, Coordsfrom, double.NaN, double.NaN, routeSystems[0]));

            Point3D curpos         = Coordsfrom;
            int     jump           = 1;
            double  actualdistance = 0;

            float maxfromwanted = (MaxRange < 100) ? (MaxRange - 1) : (100 + MaxRange * 1 / 5);       // if <100, then just make sure we jump off by 1 yr, else its a 100+1/5

            do
            {
                double distancetogo = Point3D.DistanceBetween(Coordsto, curpos);      // to go

                if (distancetogo <= MaxRange)                                         // within distance, we can go directly
                {
                    break;
                }

                Point3D travelvector      = new Point3D(Coordsto.X - curpos.X, Coordsto.Y - curpos.Y, Coordsto.Z - curpos.Z);                         // vector to destination
                Point3D travelvectorperly = new Point3D(travelvector.X / distancetogo, travelvector.Y / distancetogo, travelvector.Z / distancetogo); // per ly travel vector

                Point3D nextpos = new Point3D(curpos.X + MaxRange * travelvectorperly.X,
                                              curpos.Y + MaxRange * travelvectorperly.Y,
                                              curpos.Z + MaxRange * travelvectorperly.Z);   // where we would like to be..


                ISystem bestsystem = DB.SystemCache.GetSystemNearestTo(curpos, nextpos, MaxRange, maxfromwanted, RouteMethod, 1000);     // at least get 1/4 way there, otherwise waypoint.  Best 1000 from waypoint checked

                string sysname           = "WAYPOINT";
                double deltafromwaypoint = 0;
                double deviation         = 0;

                if (bestsystem != null)
                {
                    Point3D bestposition = new Point3D(bestsystem.X, bestsystem.Y, bestsystem.Z);
                    deltafromwaypoint = Point3D.DistanceBetween(bestposition, nextpos);     // how much in error
                    deviation         = Point3D.DistanceBetween(curpos.InterceptPoint(nextpos, bestposition), bestposition);
                    nextpos           = bestposition;
                    sysname           = bestsystem.Name;
                    routeSystems.Add(bestsystem);
                }

                info(new ReturnInfo(sysname, Point3D.DistanceBetween(curpos, nextpos), nextpos, deltafromwaypoint, deviation, bestsystem));

                actualdistance += Point3D.DistanceBetween(curpos, nextpos);
                curpos          = nextpos;
                jump++;
            } while (!StopPlotter);

            routeSystems.Add(new SystemClass(ToSystem, Coordsto.X, Coordsto.Y, Coordsto.Z));

            actualdistance += Point3D.DistanceBetween(curpos, Coordsto);

            info(new ReturnInfo(ToSystem, Point3D.DistanceBetween(curpos, Coordsto), Coordsto, double.NaN, double.NaN, routeSystems.Last()));

            info(new ReturnInfo("Straight Line Distance", traveldistance));
            info(new ReturnInfo("Travelled Distance", actualdistance));

            return(routeSystems);
        }
Example #20
0
        private void UpdateFrom(bool updatename)
        {
            changesilence = true;

            if (textBox_From.ReadOnly == false)                // if entering system name..
            {
                ISystem ds1 = _discoveryForm.history.FindSystem(SystemNameOnly(textBox_From.Text), _discoveryForm.galacticMapping);

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        if (ds1 is GalacticMapSystem)
                        {
                            GalacticMapSystem gms = (GalacticMapSystem)ds1;
                            textBox_From.Text     = gms.GalMapObject.name;
                            textBox_FromName.Text = gms.name;
                        }
                        else
                        {
                            textBox_From.Text     = ds1.name;
                            textBox_FromName.Text = ds1.name;
                        }
                    }

                    textBox_FromX.Text = ds1.x.ToString("0.00");
                    textBox_FromY.Text = ds1.y.ToString("0.00");
                    textBox_FromZ.Text = ds1.z.ToString("0.00");
                }
                else
                {
                    textBox_FromX.Text = textBox_FromY.Text = textBox_FromZ.Text = "";
                }
            }
            else
            {
                string  res = "";
                Point3D curpos;
                if (GetCoordsFrom(out curpos))
                {
                    ISystem nearest = SystemClassDB.FindNearestSystem(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.x, nearest.y, nearest.z));
                        if (distance < 0.1)
                        {
                            res = nearest.name;
                        }
                        else
                        {
                            res = nearest.name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_From.Text     = res;
                textBox_FromName.Text = res;
            }

            UpdateDistance();

            changesilence        = false;
            button_Route.Enabled = IsValid();
        }
Example #21
0
        public List <SystemClassDB> RouteIterative(Action <string> AppendText)
        {
            double traveldistance             = Point3D.DistanceBetween(coordsfrom, coordsto); // its based on a percentage of the traveldistance
            List <SystemClassDB> routeSystems = new List <SystemClassDB>();

            System.Diagnostics.Debug.WriteLine("From " + fromsys + " to  " + tosys);
            routeSystems.Add(new SystemClassDB(fromsys, coordsfrom.X, coordsfrom.Y, coordsfrom.Z));

            AppendText("Searching route from " + fromsys + " to " + tosys + " using " + metric_options[routemethod] + " metric" + Environment.NewLine);
            AppendText("Total distance: " + traveldistance.ToString("0.00") + " in " + maxrange.ToString("0.00") + "ly jumps" + Environment.NewLine);

            AppendText(Environment.NewLine);
            AppendText(string.Format("{0,-40}    Depart          @ {1,9:0.00},{2,8:0.00},{3,9:0.00}" + Environment.NewLine, fromsys, coordsfrom.X, coordsfrom.Y, coordsfrom.Z));

            Point3D curpos         = coordsfrom;
            int     jump           = 1;
            double  actualdistance = 0;

#if DEBUG
            //Console.WriteLine("-------------------------- BEGIN");
#endif
            do
            {
                double distancetogo = Point3D.DistanceBetween(coordsto, curpos);      // to go

                if (distancetogo <= maxrange)                                         // within distance, we can go directly
                {
                    break;
                }

                Point3D travelvector      = new Point3D(coordsto.X - curpos.X, coordsto.Y - curpos.Y, coordsto.Z - curpos.Z);                         // vector to destination
                Point3D travelvectorperly = new Point3D(travelvector.X / distancetogo, travelvector.Y / distancetogo, travelvector.Z / distancetogo); // per ly travel vector

                Point3D nextpos = new Point3D(curpos.X + maxrange * travelvectorperly.X,
                                              curpos.Y + maxrange * travelvectorperly.Y,
                                              curpos.Z + maxrange * travelvectorperly.Z);   // where we would like to be..

#if DEBUG
                //Console.WriteLine("Curpos " + curpos.X + "," + curpos.Y + "," + curpos.Z);
                //Console.WriteLine(" next" + nextpos.X + "," + nextpos.Y + "," + nextpos.Z);
#endif
                SystemClassDB bestsystem = SystemClassDB.GetSystemNearestTo(curpos, nextpos, maxrange, maxrange - 0.5, routemethod);

                string sysname           = "WAYPOINT";
                double deltafromwaypoint = 0;
                double deviation         = 0;

                if (bestsystem != null)
                {
                    Point3D bestposition = new Point3D(bestsystem.x, bestsystem.y, bestsystem.z);
                    deltafromwaypoint = Point3D.DistanceBetween(bestposition, nextpos);     // how much in error
                    deviation         = Point3D.DistanceBetween(curpos.InterceptPoint(nextpos, bestposition), bestposition);
                    nextpos           = bestposition;
                    sysname           = bestsystem.name;
                    routeSystems.Add(bestsystem);
                }

                AppendText(string.Format("{0,-40}{1,3} Dist:{2,8:0.00}ly @ {3,9:0.00},{4,8:0.00},{5,9:0.00} WPd:{6,8:0.00}ly Dev:{7,8:0.00}ly" + Environment.NewLine,
                                         sysname, jump, Point3D.DistanceBetween(curpos, nextpos), nextpos.X, nextpos.Y, nextpos.Z, deltafromwaypoint, deviation));

                actualdistance += Point3D.DistanceBetween(curpos, nextpos);
                curpos          = nextpos;
                jump++;
            } while (true);

            routeSystems.Add(new SystemClassDB(tosys, coordsto.X, coordsto.Y, coordsto.Z));
            actualdistance += Point3D.DistanceBetween(curpos, coordsto);
            AppendText(string.Format("{0,-40}{1,3} Dist:{2,8:0.00}ly @ {3,9:0.00},{4,8:0.00},{5,9:0.00}" + Environment.NewLine, tosys, jump, Point3D.DistanceBetween(curpos, coordsto), coordsto.X, coordsto.Y, coordsto.Z));
            AppendText(Environment.NewLine);
            AppendText(string.Format("Straight Line Distance {0,8:0.00}ly vs Travelled Distance {1,8:0.00}ly" + Environment.NewLine, traveldistance, actualdistance));

            return(routeSystems);
        }
        private void UpdateTo(object sender, string optupdateto = null)
        {
            changesilence = true;

            if (optupdateto != null)
            {
                textBox_To.Text = optupdateto;
            }

            if (sender == textBox_To)
            {
                ISystem ds1 = SystemCache.FindSystem(SystemNameOnly(textBox_To.Text), discoveryform.galacticMapping, true);
                if (ds1 != null)
                {
                    textBox_ToName.Text = ds1.Name;
                    textBox_ToX.Text    = ds1.X.ToString("0.00");
                    textBox_ToY.Text    = ds1.Y.ToString("0.00");
                    textBox_ToZ.Text    = ds1.Z.ToString("0.00");
                }
                else
                {
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
                }
            }
            else
            {
                string res = "", resname = "";

                if (GetCoordsTo(out Point3D curpos))
                {
                    ISystem           nearest    = SystemCache.FindNearestSystemTo(curpos.X, curpos.Y, curpos.Z, 100);
                    GalacticMapObject nearestgmo = discoveryform.galacticMapping.FindNearest(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        if (nearestgmo != null && nearest.Distance(curpos.X, curpos.Y, curpos.Z) > nearestgmo.GetSystem().Distance(curpos.X, curpos.Y, curpos.Z))
                        {
                            nearest = nearestgmo.GetSystem();
                        }
                    }
                    else
                    {
                        nearest = nearestgmo?.GetSystem();
                    }

                    if (nearest != null)
                    {
                        res = resname = nearest.Name;

                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.X, nearest.Y, nearest.Z));
                        if (distance > 0.1)
                        {
                            resname = nearest.Name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_To.Text     = res;
                textBox_ToName.Text = resname;
            }

            UpdateDistance();
            button_Route.Enabled = IsValid();
            changesilence        = false;
        }
Example #23
0
 /// <summary>
 /// Performs the calculous that returns the arc's length
 /// Can be overriden for derived types of arcs that are not linear.
 /// </summary>
 /// <returns></returns>
 virtual protected double CalculateLength()
 {
     return(Point3D.DistanceBetween(_StartNode.Position, _EndNode.Position));
 }
        internal static ISystem GetSystemNearestTo(IEnumerable <ISystem> systems,            // non database helper function
                                                   Point3D currentpos,
                                                   Point3D wantedpos,
                                                   double maxfromcurpos,
                                                   double maxfromwanted,
                                                   SystemsNearestMetric routemethod)
        {
            double  bestmindistance = double.MaxValue;
            ISystem nearestsystem   = null;

            foreach (var s in systems)
            {
                Point3D syspos = new Point3D(s.X, s.Y, s.Z);
                double  distancefromwantedx2 = Point3D.DistanceBetweenX2(wantedpos, syspos);  // range between the wanted point and this, ^2
                double  distancefromcurposx2 = Point3D.DistanceBetweenX2(currentpos, syspos); // range between the wanted point and this, ^2

                // ENSURE its withing the circles now
                if (distancefromcurposx2 <= (maxfromcurpos * maxfromcurpos) && distancefromwantedx2 <= (maxfromwanted * maxfromwanted))
                {
                    if (routemethod == SystemsNearestMetric.IterativeNearestWaypoint)
                    {
                        if (distancefromwantedx2 < bestmindistance)
                        {
                            nearestsystem   = s;
                            bestmindistance = distancefromwantedx2;
                        }
                    }
                    else
                    {
                        Point3D interceptpoint = currentpos.InterceptPoint(wantedpos, syspos);      // work out where the perp. intercept point is..
                        double  deviation      = Point3D.DistanceBetween(interceptpoint, syspos);
                        double  metric         = 1E39;

                        if (routemethod == SystemsNearestMetric.IterativeMinDevFromPath)
                        {
                            metric = deviation;
                        }
                        else if (routemethod == SystemsNearestMetric.IterativeMaximumDev100Ly)
                        {
                            metric = (deviation <= 100) ? distancefromwantedx2 : metric;        // no need to sqrt it..
                        }
                        else if (routemethod == SystemsNearestMetric.IterativeMaximumDev250Ly)
                        {
                            metric = (deviation <= 250) ? distancefromwantedx2 : metric;
                        }
                        else if (routemethod == SystemsNearestMetric.IterativeMaximumDev500Ly)
                        {
                            metric = (deviation <= 500) ? distancefromwantedx2 : metric;
                        }
                        else if (routemethod == SystemsNearestMetric.IterativeWaypointDevHalf)
                        {
                            metric = Math.Sqrt(distancefromwantedx2) + deviation / 2;
                        }
                        else
                        {
                            throw new ArgumentOutOfRangeException(nameof(routemethod));
                        }

                        if (metric < bestmindistance)
                        {
                            nearestsystem   = s;
                            bestmindistance = metric;
                        }
                    }
                }
            }

            return(nearestsystem);
        }