private void PrepareNodes(Graph G, out List<Node> nodes, float maxrange, int mode) { List<SystemClass> systems = SystemData.SystemList; nodes = new List<Node>(); SystemClass arcsystem; float distance, maxrangex2 = maxrange * maxrange; Node N2; float weight = 1; float dx, dy, dz; Stopwatch sw = new Stopwatch(); sw.Start(); SystemClass system; Node N1; for (int ii = 0; ii < systems.Count; ii++) { system = systems[ii]; N1 = new Node(system.x, system.y, system.z, system); G.AddNodeWithNoChk(N1); nodes.Add(N1); } sw.Stop(); AppendText("Add stars: " + sw.Elapsed.TotalSeconds.ToString("0.000s") + Environment.NewLine); sw.Restart(); for (int ii = 0; ii < systems.Count; ii++) { system = systems[ii]; N1 = nodes[ii]; for (int jj = ii; jj < systems.Count; jj++) { arcsystem = systems[jj]; dx = (float)(system.x - arcsystem.x); dy = (float)(system.y - arcsystem.y); dz = (float)(system.z - arcsystem.z); distance = dx * dx + dy * dy + dz * dz; //distance = (float)((system.x - arcsystem.x) * (system.x - arcsystem.x) + (system.y - arcsystem.y) * (system.y - arcsystem.y) + (system.z - arcsystem.z) * (system.z - arcsystem.z)); if (distance > 0 && distance <= maxrangex2) { N2 = nodes[jj]; 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); }
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); }