예제 #1
0
        public ArborPoint toScreen(ArborPoint pt)
        {
            if (fViewBounds == null)
            {
                return(ArborPoint.Null);
            }

            ArborPoint vd = fViewBounds.RightBottom.sub(fViewBounds.LeftTop);
            double     sx = margins[3] + pt.sub(fViewBounds.LeftTop).div(vd.X).X *(this.fScreenWidth - (margins[1] + margins[3]));
            double     sy = margins[0] + pt.sub(fViewBounds.LeftTop).div(vd.Y).Y *(this.fScreenHeight - (margins[0] + margins[2]));

            return(new ArborPoint(sx, sy));
        }
예제 #2
0
        public ArborNode nearest(int sx, int sy)
        {
            ArborPoint x = this.fromScreen(sx, sy);

            ArborNode resNode = null;
            double    minDist = +1.0;

            foreach (ArborNode node in this.fNodes)
            {
                ArborPoint z = node.Pt;
                if (z.exploded())
                {
                    continue;
                }

                double dist = z.sub(x).magnitude();
                if (dist < minDist)
                {
                    resNode = node;
                    minDist = dist;
                }
            }

            //minDist = this.toScreen(resNode.Pt).sub(this.toScreen(x)).magnitude();
            return(resNode);
        }
예제 #3
0
        private void updateGraphBounds()
        {
            ArborPoint lt = new ArborPoint(-1, -1);
            ArborPoint rb = new ArborPoint(1, 1);

            foreach (ArborNode node in this.fNodes)
            {
                ArborPoint pt = node.Pt;
                if (pt.exploded())
                {
                    continue;
                }

                if (pt.X < lt.X)
                {
                    lt.X = pt.X;
                }
                if (pt.Y < lt.Y)
                {
                    lt.Y = pt.Y;
                }
                if (pt.X > rb.X)
                {
                    rb.X = pt.X;
                }
                if (pt.Y > rb.Y)
                {
                    rb.Y = pt.Y;
                }
            }

            lt.X -= 1.2;
            lt.Y -= 1.2;
            rb.X += 1.2;
            rb.Y += 1.2;

            ArborPoint sz   = rb.sub(lt);
            ArborPoint cent = lt.add(sz.div(2));
            ArborPoint d    = new ArborPoint(Math.Max(sz.X, 4.0), Math.Max(sz.Y, 4.0)).div(2);

            this.fGraphBounds = new PSBounds(cent.sub(d), cent.add(d));
        }
예제 #4
0
 public BarnesHutTree(ArborPoint origin, ArborPoint h, double dist)
 {
     this.fDist = dist * dist;
     this.fRoot = new Branch(origin, h.sub(origin));
 }
예제 #5
0
        private void updateVelocityAndPosition(double dt)
        {
            int size = fNodes.Count;

            if (size == 0)
            {
                EnergySum  = 0;
                EnergyMax  = 0;
                EnergyMean = 0;
                return;
            }

            double eSum = 0;
            double eMax = 0;

            // calc center drift
            ArborPoint rr = new ArborPoint(0, 0);

            foreach (ArborNode node in fNodes)
            {
                rr = rr.sub(node.Pt);
            }
            ArborPoint drift = rr.div(size);

            // main updates loop
            foreach (ArborNode node in fNodes)
            {
                // apply center drift
                node.applyForce(drift);

                // apply center gravity
                if (ParamGravity)
                {
                    ArborPoint q = node.Pt.mul(-1);
                    node.applyForce(q.mul(ParamRepulsion / 100));
                }

                // update velocities
                if (node.Fixed)
                {
                    node.V = new ArborPoint(0, 0);
                }
                else
                {
                    node.V = node.V.add(node.F.mul(dt));
                    node.V = node.V.mul(1 - ParamFriction);

                    double r = node.V.magnitudeSquare();
                    if (r > 1000000)
                    {
                        node.V = node.V.div(r);
                    }
                }

                node.F.X = node.F.Y = 0;

                // update positions
                node.Pt = node.Pt.add(node.V.mul(dt));

                // update energy
                double z = node.V.magnitudeSquare();
                eSum += z;
                eMax  = Math.Max(z, eMax);
            }

            EnergySum  = eSum;
            EnergyMax  = eMax;
            EnergyMean = eSum / size;
        }