public ArborViewer() { base.BorderStyle = BorderStyle.Fixed3D; base.TabStop = true; base.BackColor = Color.White; base.DoubleBuffered = true; base.SetStyle(ControlStyles.AllPaintingInWmPaint, true); base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // repulsion - отталкивание, stiffness - тугоподвижность, friction - сила трения this.fSys = new ArborSystem(10000, 500 /*1000*/, 0.1, this); this.fSys.setScreenSize(this.Width, this.Height); this.fSys.AutoStop = false; this.fEnergyDebug = false; this.fDrawFont = new Font("Calibri", 9); this.fStrFormat = new StringFormat(); this.fStrFormat.Alignment = StringAlignment.Center; this.fStrFormat.LineAlignment = StringAlignment.Center; this.fBlackBrush = new SolidBrush(Color.Black); this.fWhiteBrush = new SolidBrush(Color.White); this.fDragged = null; this.fNodesDragging = false; }
public ArborNode addNode(string sign) { ArborPoint lt = this.fGraphBounds.LeftTop; ArborPoint rb = this.fGraphBounds.RightBottom; double xx = lt.X + (rb.X - lt.X) * ArborSystem.NextRndDouble(); double yy = lt.Y + (rb.Y - lt.Y) * ArborSystem.NextRndDouble(); return(this.addNode(sign, xx, yy)); }
public static ArborPoint newRnd(double a = 5) { return(new ArborPoint(2 * a * (ArborSystem.NextRndDouble() - 0.5), 2 * a * (ArborSystem.NextRndDouble() - 0.5))); }
public void insert(ArborNode j) { try { Branch f = fRoot; List <ArborNode> gst = new List <ArborNode>(); gst.Add(j); while (gst.Count > 0) { ArborNode h = gst[0]; gst.RemoveAt(0); double m = h.Mass; int qd = getQuad(h, f); object fp = f.Q[qd]; if (fp == null) { f.Q[qd] = h; f.Mass += m; f.Pt = f.Pt.add(h.Pt.mul(m)); } else { if (fp is Branch) { f.Mass += m; f.Pt = f.Pt.add(h.Pt.mul(m)); f = fp as Branch; gst.Insert(0, h); } else { ArborPoint l = f.Size.div(2); ArborPoint n = new ArborPoint(f.Origin.X, f.Origin.Y); if (qd == QSe || qd == QSw) { n.Y += l.Y; } if (qd == QNe || qd == QSe) { n.X += l.X; } ArborNode o = fp as ArborNode; fp = new Branch(n, l); f.Q[qd] = fp; f.Mass = m; f.Pt = h.Pt.mul(m); f = fp as Branch; if (o.Pt.X == h.Pt.X && o.Pt.Y == h.Pt.Y) { double k = l.X * 0.08; double i = l.Y * 0.08; o.Pt.X = Math.Min(n.X + l.X, Math.Max(n.X, o.Pt.X - k / 2 + ArborSystem.NextRndDouble() * k)); o.Pt.Y = Math.Min(n.Y + l.Y, Math.Max(n.Y, o.Pt.Y - i / 2 + ArborSystem.NextRndDouble() * i)); } gst.Add(o); gst.Insert(0, h); } } } } catch (Exception ex) { Debug.WriteLine("BarnesHutTree.insert(): " + ex.Message); } }