示例#1
0
 public static bool GetTargetPosition(out string name, out Point3D t)
 {
     double x, y, z;
     bool ret = GetTargetPosition(out name, out x, out y, out z);
     t = new Point3D(x, y, z);
     return ret;
 }
示例#2
0
文件: Node.cs 项目: snmslavk/AStar
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="PositionX">X coordinate.</param>
 /// <param name="PositionY">Y coordinate.</param>
 /// <param name="PositionZ">Z coordinate.</param>
 public Node(double PositionX, double PositionY, double PositionZ)
 {
     _Position = new Point3D(PositionX, PositionY, PositionZ);
     _Passable = true;
     _IncomingArcs = new ArrayList();
     _OutgoingArcs = new ArrayList();
 }
示例#3
0
        public override bool GetData(EDDiscoveryForm _discoveryForm)
        {
            if(_discoveryForm.RouteControl.RouteSystems==null
                || _discoveryForm.RouteControl.RouteSystems.Count==0)
            {

                MessageBox.Show(String.Format("Please create a route on the route tab"), TITLE);
                return false;
            }

            Point3D last = null;
            foreach (SystemClass 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;
        }
示例#4
0
        private void Route(string s1, string s2, float maxrange, int mode)
        {
            EDDiscovery2.DB.ISystem ds1 = SystemData.GetSystem(s1);
            EDDiscovery2.DB.ISystem ds2 = SystemData.GetSystem(s2);

            if (ds1 == null)          // warn here, quicker to complain than waiting for nodes to populate.
            {
                AppendText("Start system:  " + s1 + " unknown");
                return;
            }
            if (ds2 == null)
            {
                AppendText("Destination system:  " + s2 + " unknown");
                return;
            }

            double earea = 10.0;            // add a little to the box for first/end points allowing out of box systems
            Point3D minpos = new EMK.LightGeometry.Point3D(
                    Math.Min(ds1.x, ds2.x) - earea,
                    Math.Min(ds1.y, ds2.y) - earea,
                    Math.Min(ds1.z, ds2.z) - earea );
            Point3D maxpos = new EMK.LightGeometry.Point3D(
                    Math.Max(ds1.x, ds2.x) + earea,
                    Math.Max(ds1.y, ds2.y)+ earea,
                    Math.Max(ds1.z, ds2.z) + earea );

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

            Stopwatch sw = new Stopwatch();

            G = new Graph();                    // need to compute each time as systems in range changes each time
            PrepareNodes(G, maxrange, mode,minpos,maxpos);

            AStar AS = new AStar(G);

            Node start, stop;

            start = G.GetNodes.FirstOrDefault(x => x.System.SearchName == s1.ToLower());
            stop = G.GetNodes.FirstOrDefault(x => x.System.SearchName == s2.ToLower());

            bool res;

            sw = new Stopwatch();

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

            AppendText("Searching route from " + ds1.name + " to " + ds2.name + Environment.NewLine);
            AppendText("Find route Time: " + sw.Elapsed.TotalSeconds.ToString("0.000s") + Environment.NewLine);
            AppendText("Total distance: " + SystemData.Distance(s1, s2).ToString("0.00") + Environment.NewLine);
            AppendText("Max jumprange:" + maxrange + Environment.NewLine);

            if (res)
            {
                AppendText(Environment.NewLine + "Depart " + ds1.name + Environment.NewLine);

                double totdist = 0;
                int jumps = 0;

                foreach (Arc A in AS.PathByArcs)
                {
                    double dist = SystemData.Distance(A.StartNode.System.name, A.EndNode.System.name);
                    AppendText(string.Format("{0,-30}Dist: {1:0.00} ly" + Environment.NewLine, A.EndNode.System.name, dist));

                    totdist += dist;
                    jumps++;

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

                AppendText(Environment.NewLine + "Total distance: " + totdist.ToString("0.00") + Environment.NewLine);
                AppendText("Jumps: " + jumps + Environment.NewLine);

                // JArray ja = Path2JSON(AS);
            }
            else
                AppendText(Environment.NewLine + "NO Solution found - jump distance is too small or not enough star data between systems" + Environment.NewLine);
        }
示例#5
0
        private string DistToStar(VisitedSystemsClass vscentry, Point3D tpos)
        {
            string res = "";
            if (!double.IsNaN(tpos.X))
            {
                double dist = VisitedSystemsClass.Distance(vscentry, tpos);
                if (dist >= 0)
                    res = dist.ToString("0.00");
            }

            return res;
        }
示例#6
0
        public static SystemClass GetSystemNearestTo(Point3D curpos, Point3D wantedpos, double maxfromcurpos, double maxfromwanted,
            int routemethod)
        {
            SystemClass nearestsystem = null;

            try
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    string sqlquery = "SELECT EdsmId, x, y, z " +                   // DO a square test for speed, then double check its within the circle later..
                                      "FROM EdsmSystems " +
                                      "WHERE x >= @xc - @maxfromcurpos " +
                                      "AND x <= @xc + @maxfromcurpos " +
                                      "AND y >= @yc - @maxfromcurpos " +
                                      "AND y <= @yc + @maxfromcurpos " +
                                      "AND z >= @zc - @maxfromcurpos " +
                                      "AND z <= @zc + @maxfromcurpos " +
                                      "AND x >= @xw - @maxfromwanted " +
                                      "AND x <= @xw + @maxfromwanted " +
                                      "AND y >= @yw - @maxfromwanted " +
                                      "AND y <= @yw + @maxfromwanted " +
                                      "AND z >= @zw - @maxfromwanted " +
                                      "AND z <= @zw + @maxfromwanted ";

                    using (DbCommand cmd = cn.CreateCommand(sqlquery))
                    {
                        cmd.AddParameterWithValue("xw", (long)(wantedpos.X * XYZScalar));
                        cmd.AddParameterWithValue("yw", (long)(wantedpos.Y * XYZScalar));
                        cmd.AddParameterWithValue("zw", (long)(wantedpos.Z * XYZScalar));
                        cmd.AddParameterWithValue("maxfromwanted", (long)(maxfromwanted * XYZScalar));     //squared

                        cmd.AddParameterWithValue("xc", (long)(curpos.X * XYZScalar));
                        cmd.AddParameterWithValue("yc", (long)(curpos.Y * XYZScalar));
                        cmd.AddParameterWithValue("zc", (long)(curpos.Z * XYZScalar));
                        cmd.AddParameterWithValue("maxfromcurpos", (long)(maxfromcurpos * XYZScalar));     //squared

                        double bestmindistance = double.MaxValue;
                        long nearestedsmid = -1;

                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                long edsmid = (long)reader[0];

                                //SystemClass sys = GetSystem(edsmid, null, SystemIDType.EdsmId);  Console.WriteLine("FOund {0} at {1} {2} {3}", sys.name, sys.x, sys.y, sys.z);

                                if (System.DBNull.Value != reader["x"]) // paranoid check, it could be null in db
                                {
                                    Point3D syspos = new Point3D(((double)(long)reader[1])/XYZScalar, ((double)(long)reader[2])/XYZScalar, ((double)(long)reader[3])/XYZScalar);

                                    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

                                                                                                                // ENSURE its withing the circles now
                                    if (distancefromcurposx2 <= (maxfromcurpos * maxfromcurpos) && distancefromwantedx2 <= (maxfromwanted * maxfromwanted))
                                    {
                                        if (routemethod == metric_nearestwaypoint)
                                        {
                                            if (distancefromwantedx2 < bestmindistance)
                                            {
                                                nearestedsmid = edsmid;
                                                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 if (routemethod == metric_waypointdev2)
                                                metric = Math.Sqrt(distancefromwantedx2) + deviation / 2;

                                            if (metric < bestmindistance)
                                            {
                                                nearestedsmid = edsmid;
                                                bestmindistance = metric;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (nearestedsmid != -1)
                            nearestsystem = GetSystem(nearestedsmid, cn, SystemIDType.EdsmId);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }

            return nearestsystem;
        }
示例#7
0
 public static double DistanceBetweenX2(Point3D P1, Point3D P2)
 {
     return (P1.X - P2.X) * (P1.X - P2.X) + (P1.Y - P2.Y) * (P1.Y - P2.Y) + (P1.Z - P2.Z) * (P1.Z - P2.Z);
 }
示例#8
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;
 }
示例#9
0
文件: Node.cs 项目: snmslavk/AStar
 /// <summary>
 /// Modifies X, Y and Z coordinates
 /// </summary>
 /// <param name="PositionX">X coordinate.</param>
 /// <param name="PositionY">Y coordinate.</param>
 /// <param name="PositionZ">Z coordinate.</param>
 public void ChangeXYZ(double PositionX, double PositionY, double PositionZ)
 {
     Position = new Point3D(PositionX, PositionY, PositionZ);
 }
示例#10
0
 // go thru setting the lastknowsystem
 public static VisitedSystemsClass FindByPos(List<VisitedSystemsClass> visitedSystems, Point3D p, double limit)
 {
     if (visitedSystems != null)
     {
         VisitedSystemsClass vs = visitedSystems.FindLast(x => x.curSystem.HasCoordinate &&
                                         Math.Abs(x.curSystem.x - p.X) < limit &&
                                         Math.Abs(x.curSystem.y - p.Y) < limit &&
                                         Math.Abs(x.curSystem.z - p.Z) < limit);
         return vs;
     }
     else
         return null;
 }
示例#11
0
 // i = 0 to 1.0, on the vector from 000
 public static Point3D PointAlongVector(Point3D x1, double i)
 {
     return new Point3D(x1.X * i, x1.Y * i, x1.Z * i);
 }
示例#12
0
 // i = 0 to 1.0, on the path. Negative before the path, >1 after the path
 public Point3D PointAlongPath(Point3D x1, double i)
 {
     return new Point3D(this.X + (x1.X - this.X) * i, this.Y + (x1.Y - this.Y) * i, this.Z + (x1.Z - this.Z) * i);
 }
示例#13
0
 public Point3D Subtract(Point3D other )
 {
     return new Point3D(this.X - other.X, this.Y - other.Y, this.Z - other.Z);
 }
示例#14
0
 // from this(x1) to X2, given a point x0, where do the perpendiclar intercept?
 public Point3D InterceptPoint( Point3D x2, Point3D x0 )
 {
     return PointAlongPath(x2, InterceptPercent(x2, x0));
 }
示例#15
0
 // % along the path THIS(x1)->X2 that a vector from X0 perpendicular meets it
 public double InterceptPercent( Point3D x2, Point3D x0)
 {
     double dotp = (this.X - x0.X) * (x2.X - this.X) + (this.Y - x0.Y) * (x2.Y - this.Y) + (this.Z - x0.Z) * (x2.Z - this.Z);
     double mag2 = ((x2.X - this.X) * (x2.X - this.X) + (x2.Y - this.Y) * (x2.Y - this.Y) + (x2.Z - this.Z) * (x2.Z - this.Z));
     return -dotp / mag2;              // its -((x1-x0) dotp (x2-x1) / |x2-x1|^2)
 }
示例#16
0
 public double DOTP( Point3D other )
 {
     return this.X * other.X + this.Y * other.Y + this.Z * other.Z;
 }
示例#17
0
        private void UpdateRow(DataGridView vsc, DataGridViewRow vscrow, bool addit, int insertat , Point3D tpos)
        {
            Debug.Assert(vscrow != null && vsc != null);

            if (!vscrow.Visible)            // may not be visible due to being turned off.. if so, reject.
                return;

            Color rowc = CSel(vsc.Rows[vscrow.Index].DefaultCellStyle.ForeColor, vsc.ForeColor);
            if (rowc.GetBrightness() < 0.15)       // override if its too dark..
                rowc = Color.White;

            int pos = 4;

            List<ControlEntryProperties> cep = new List<ControlEntryProperties>();

            if ((config & Configuration.showEDSMButton) != 0)
                cep.Add(new ControlEntryProperties(butfont, ref pos, 40 * tabscalar, panel_grip.ForeColor, "!!<EDSMBUT:" + (string)vscrow.Cells[1].Value));

            if ((config & Configuration.showTime) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, ((DateTime)vscrow.Cells[0].Value).ToString("HH:mm.ss")));

            cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[1].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[1].Value));

            if ((config & Configuration.showDistance) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 50 * tabscalar, rowc, (string)vscrow.Cells[2].Value));

            if (toolStripComboBoxOrder.SelectedIndex == 0 && (config & Configuration.showNotes) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[3].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[3].Value));

            VisitedSystemsClass vscentry = (VisitedSystemsClass)vscrow.Cells[EDDiscovery.TravelHistoryControl.TravelHistoryColumns.SystemName].Tag;

            if (toolStripComboBoxOrder.SelectedIndex == 2 && (config & Configuration.showDistancePerStar) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, DistToStar(vscentry, tpos)));

            if ((config & Configuration.showXYZ) != 0 && vscentry != null)
            {
                string xv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.x.ToString("0.00") : "-";
                string yv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.y.ToString("0.00") : "-";
                string zv = (vscentry.curSystem.HasCoordinate) ? vscentry.curSystem.z.ToString("0.00") : "-";

                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, xv));
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 50 * tabscalar, rowc, yv));
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[0].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, zv));
            }

            if (toolStripComboBoxOrder.SelectedIndex > 0 && (config & Configuration.showNotes) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[3].DefaultCellStyle.Font, vsc.Font), ref pos, 150 * tabscalar, rowc, (string)vscrow.Cells[3].Value));

            if (toolStripComboBoxOrder.SelectedIndex < 2 && (config & Configuration.showDistancePerStar) != 0)
                cep.Add(new ControlEntryProperties(FontSel(vsc.Columns[2].DefaultCellStyle.Font, vsc.Font), ref pos, 60 * tabscalar, rowc, DistToStar(vscentry, tpos)));

            if (addit)
            {
                int row = lt.Add(vscrow.Index,cep, insertat);        // row on the summary screen..  remember which row it came from
                lt.SetFormat(row, cep , blackBoxAroundTextToolStripMenuItem.Checked);
            }
            else
            {
                lt.RefreshTextAtID(vscrow.Index,cep);      // refresh this one with rowid= index
            }
        }
示例#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
            routeSystems = new List<SystemClass>();
            routeSystems.Add(SystemClass.GetSystem(textBox_From.Text));

            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
                SystemClass bestsystem = SystemClass.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(SystemClass.GetSystem(textBox_To.Text));
            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));
        }
示例#19
0
 public static double Distance(VisitedSystemsClass s1, Point3D p)
 {
     return Distance(s1, p.X, p.Y, p.Z);
 }
示例#20
0
 // % along the path 0,0,0->X2 that a vector from X0 perpendicular meets it
 public static double InterceptPercent000(Point3D x2, Point3D x0)
 {
     double dotp = (-x0.X) * (x2.X) + (-x0.Y) * (x2.Y) + (-x0.Z) * (x2.Z);       // this is 0,0,0 in effect, so remove terms
     double mag2 = ((x2.X) * (x2.X) + (x2.Y) * (x2.Y) + (x2.Z) * (x2.Z));
     return -dotp / mag2;              // its -((x1-x0) dotp (x2-x1) / |x2-x1|^2)    where x0 =0,0,0
 }
示例#21
0
        private bool GetCoordsTo(out Point3D pos)
        {
            double x = 0, y = 0, z = 0;

            bool worked = System.Double.TryParse(textBox_ToX.Text, out x) &&
                            System.Double.TryParse(textBox_ToY.Text, out y) &&
                            System.Double.TryParse(textBox_ToZ.Text, out z);
            pos = new Point3D(x, y, z);
            return worked;
        }
示例#22
0
        private string DistToStar(HistoryEntry he, Point3D tpos)
        {
            string res = "";
            if (!double.IsNaN(tpos.X))
            {
                double dist = SystemClass.Distance(he.System, tpos.X, tpos.Y, tpos.Z);
                if (dist >= 0)
                    res = dist.ToString("0.00");
            }

            return res;
        }
示例#23
0
        private void RouteMain()
        {
            float maxrange = 30;
            string maxrangetext = "";
            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
                maxrangetext = 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";

            if (!float.TryParse(maxrangetext, out maxrange)) maxrange = 30;
            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(() => ToggleButtons(true)));
                    return;
                }
            }

            RouteIterative(fromsys, usingcoordsfrom, coordsfrom,
                            tosys, usingcoordsto, coordsto,
                              maxrange, routemethod);

            this.Invoke(new Action(() => ToggleButtons(true)));
        }
示例#24
0
        void DrawHistoryEntry(HistoryEntry he, int rowpos, Point3D tpos , Color textcolour , Color backcolour )
        {
            List<string> coldata = new List<string>();                      // First we accumulate the strings
            List<int> tooltipattach = new List<int>();

            if (Config(Configuration.showTime))
                coldata.Add((EDDiscoveryForm.EDDConfig.DisplayUTC ? he.EventTimeUTC : he.EventTimeLocal).ToString("HH:mm.ss"));

            if (Config(Configuration.showDescription))
            {
                tooltipattach.Add(coldata.Count);
                coldata.Add(he.EventSummary.Replace("\r\n", " "));
            }

            if (Config(Configuration.showInformation))
            {
                tooltipattach.Add(coldata.Count);
                coldata.Add(he.EventDescription.Replace("\r\n", " "));
            }

            if (layoutorder == 0 && Config(Configuration.showNotes))
            {
                SystemNoteClass snc = SystemNoteClass.GetNoteOnJournalEntry(he.Journalid);
                if (snc == null && he.IsFSDJump)
                    snc = SystemNoteClass.GetNoteOnSystem(he.System.name, he.System.id_edsm);

                coldata.Add((snc != null) ? snc.Note.Replace("\r\n", " ") : "");
            }

            bool showdistance = !Config(Configuration.showDistancesOnFSDJumpsOnly) || he.IsFSDJump;

            if (layoutorder == 2 && Config(Configuration.showDistancePerStar))
                coldata.Add(showdistance ? DistToStar(he, tpos) : "");

            if (Config(Configuration.showXYZ))
            {
                coldata.Add((he.System.HasCoordinate && showdistance) ? he.System.x.ToString("0.00") : "");
                coldata.Add((he.System.HasCoordinate && showdistance) ? he.System.y.ToString("0.00") : "");
                coldata.Add((he.System.HasCoordinate && showdistance) ? he.System.z.ToString("0.00") : "");
            }

            if (layoutorder > 0 && Config(Configuration.showNotes))
            {
                SystemNoteClass snc = SystemNoteClass.GetNoteOnJournalEntry(he.Journalid);
                if (snc == null && he.IsFSDJump)
                    snc = SystemNoteClass.GetNoteOnSystem(he.System.name, he.System.id_edsm);

                coldata.Add((snc != null) ? snc.Note.Replace("\r\n", " ") : "");
            }

            if (layoutorder < 2 && Config(Configuration.showDistancePerStar))
                coldata.Add(showdistance ? DistToStar(he, tpos) : "");

            int colnum = 0;

            if (Config(Configuration.showEDSMButton))
            {
                Image edsm = EDDiscovery.Properties.Resources.edsm;
                pictureBox.AddImage(new Rectangle(scanpostextoffset.X+columnpos[colnum++], rowpos, edsm.Width, edsm.Height), edsm, he, "Click to view information on EDSM");
            }

            string tooltip = he.EventSummary + Environment.NewLine + he.EventDescription + Environment.NewLine + he.EventDetailedInfo;

            for (int i = 0; i < coldata.Count; i++)             // then we draw them, allowing them to overfill columns if required
            {
                int nextfull = i+1;
                for (; nextfull < coldata.Count && Config(Configuration.showExpandOverColumns) && coldata[nextfull].Length == 0; nextfull++)
                { }

                AddColText(colnum + i, colnum + nextfull , rowpos, coldata[i], textcolour, backcolour, tooltipattach.Contains(i) ? tooltip : null);
            }
        }
示例#25
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;
 }
示例#26
0
 /// <summary>
 /// Returns the distance between two points.
 /// </summary>
 /// <param name="P1">First point.</param>
 /// <param name="P2">Second point.</param>
 /// <returns>Distance value.</returns>
 public static double DistanceBetween(Point3D P1, Point3D P2)
 {
     return(Math.Sqrt((P1.X - P2.X) * (P1.X - P2.X) + (P1.Y - P2.Y) * (P1.Y - P2.Y)));
 }
示例#27
0
        public static SystemClass GetSystemNearestTo(Point3D curpos, Point3D wantedpos, double maxfromcurpos, double maxfromwanted,
            int routemethod)
        {
            SystemClass nearestsystem = null;

            try
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    string sqlquery = "SELECT EdsmId, x, y, z " +
                                      "FROM EdsmSystems " +
                                      "WHERE x >= @xc - @maxfromcurpos " +
                                      "AND x <= @xc + @maxfromcurpos " +
                                      "AND y >= @yc - @maxfromcurpos " +
                                      "AND y <= @yc + @maxfromcurpos " +
                                      "AND z >= @zc - @maxfromcurpos " +
                                      "AND z <= @zc + @maxfromcurpos " +
                                      "AND x >= @xw - @maxfromwanted " +
                                      "AND x <= @xw + @maxfromwanted " +
                                      "AND y >= @yw - @maxfromwanted " +
                                      "AND y <= @yw + @maxfromwanted " +
                                      "AND z >= @zw - @maxfromwanted " +
                                      "AND z <= @zw + @maxfromwanted ";

                    using (DbCommand cmd = cn.CreateCommand(sqlquery))
                    {
                        cmd.AddParameterWithValue("@xw", wantedpos.X);
                        cmd.AddParameterWithValue("@yw", wantedpos.Y);
                        cmd.AddParameterWithValue("@zw", wantedpos.Z);
                        cmd.AddParameterWithValue("@maxfromwanted", maxfromwanted * maxfromwanted);     //squared

                        cmd.AddParameterWithValue("@xc", curpos.X);
                        cmd.AddParameterWithValue("@yc", curpos.Y);
                        cmd.AddParameterWithValue("@zc", curpos.Z);
                        cmd.AddParameterWithValue("@maxfromcurrent", maxfromcurpos * maxfromcurpos);     //squared

                        double bestmindistance = double.MaxValue;

                        using (DbDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                string name = (string)reader["name"];
                                long id = (long)reader["id"];

                                if (System.DBNull.Value != reader["x"]) // paranoid check, it could be null in db
                                {

                                    Point3D syspos = new Point3D((double)reader["x"], (double)reader["y"], (double)reader["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 (routemethod == metric_nearestwaypoint)
                                    {
                                        if (distancefromwantedx2 < bestmindistance)
                                        {
                                            nearestsystem = GetSystem(id);
                                            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 if (routemethod == metric_waypointdev2)
                                            metric = Math.Sqrt(distancefromwantedx2) + deviation / 2;

                                        if (metric < bestmindistance)
                                        {
                                            nearestsystem = GetSystem(id);
                                            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"));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }

            return nearestsystem;
        }
示例#28
0
 /// <summary>
 /// Returns the distance between two points.
 /// </summary>
 /// <param name="P1">First point.</param>
 /// <param name="P2">Second point.</param>
 /// <returns>Distance value.</returns>
 public static double DistanceBetween(Point3D P1, Point3D P2)
 {
     return Math.Sqrt((P1.X-P2.X)*(P1.X-P2.X)+(P1.Y-P2.Y)*(P1.Y-P2.Y));
 }
示例#29
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);
            }
        }
示例#30
0
        /// <summary>
        /// Returns the projection of a point on the line defined with two other points.
        /// When the projection is out of the segment, then the closest extremity is returned.
        /// </summary>
        /// <exception cref="ArgumentNullException">None of the arguments can be null.</exception>
        /// <exception cref="ArgumentException">P1 and P2 must be different.</exception>
        /// <param name="Pt">Point to project.</param>
        /// <param name="P1">First point of the line.</param>
        /// <param name="P2">Second point of the line.</param>
        /// <returns>The projected point if it is on the segment / The closest extremity otherwise.</returns>
        public static Point3D ProjectOnLine(Point3D Pt, Point3D P1, Point3D P2)
        {
            if ( Pt==null || P1==null || P2==null ) throw new ArgumentNullException("None of the arguments can be null.");
            if ( P1.Equals(P2) ) throw new ArgumentException("P1 and P2 must be different.");
            Vector3D VLine = new Vector3D(P1, P2);
            Vector3D V1Pt = new Vector3D(P1, Pt);
            Vector3D Translation = VLine*(VLine|V1Pt)/VLine.SquareNorm;
            Point3D Projection = P1+Translation;

            Vector3D V1Pjt = new Vector3D(P1, Projection);
            double D1 = V1Pjt|VLine;
            if ( D1<0 ) return P1;

            Vector3D V2Pjt = new Vector3D(P2, Projection);
            double D2 = V2Pjt|VLine;
            if ( D2>0 ) return P2;

            return Projection;
        }
示例#31
0
		/// <summary>
		/// Constructs a Vector3D with two points.
		/// </summary>
		/// <param name="P1">First point of the vector.</param>
		/// <param name="P2">Second point of the vector.</param>
		public Vector3D(Point3D P1, Point3D P2)
		{
			DX = P2.X-P1.X; DY = P2.Y-P1.Y; DZ = P2.Z-P1.Z;
		}
示例#32
0
        private void PrepareNodes(Graph G, float maxrange, int mode, Point3D minpos , Point3D maxpos)
        {
            List<SystemClass> systems = SystemData.SystemList;
            float distance, maxrangex2 = maxrange * maxrange;
            Node N1,N2;
            float weight = 1;
            float dx, dy, dz;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            SystemClass system;

            for (int ii = 0; ii < systems.Count; ii++)
            {
                system = systems[ii];
                                                    // screening out stars reduces number and makes the arc calculator much quicker.
                if (system.x >= minpos.X && system.x <= maxpos.X &&
                    system.y >= minpos.Y && system.y <= maxpos.Y &&
                    system.z >= minpos.Z && system.z <= maxpos.Z )
                {
                    N1 = new Node(system.x, system.y, system.z, system);
                    G.AddNodeWithNoChk(N1);
                }
            }

            sw.Stop();

            AppendText("Add stars: " + sw.Elapsed.TotalSeconds.ToString("0.000s") + Environment.NewLine);
            AppendText("No stars within bounds " + G.Count + Environment.NewLine);

            sw.Restart();
            for (int ii = 0; ii < G.Count; ii++)
            {
                N1 = G.GetN(ii);

                for (int jj = ii; jj < G.Count; jj++)
                {
                    N2 = G.GetN(jj);

                    dx = (float)(N1.X - N2.X);
                    dy = (float)(N1.Y - N2.Y);
                    dz = (float)(N1.Z - N2.Z);
                    distance = dx * dx + dy * dy + dz * dz;

                    if (distance > 0 && distance <= maxrangex2)
                    {
                        if (mode == 1)
                            weight = (float)(1 / distance);

                        G.AddArcWithNoChk(N1, N2, weight);
                        G.AddArcWithNoChk(N2, N1, weight);
                    }
                }
            }

            sw.Stop();
            //Console.WriteLine("Create arcs: {0}", sw.Elapsed);
            AppendText("Create arcs: " + sw.Elapsed.TotalSeconds.ToString("0.000s") + Environment.NewLine);
        }