Beispiel #1
0
        public void Simple2NodeGraph()
        {
            Graph g = new Graph ();
            Node q1 = new Node ();
            Node q2 = new Node ();

            q1.Location = new Point(){ X = 1, Y = 5, Z = 0 };
            q2.Location = new Point(){ X = 0, Y = -2, Z = 0 };

            g.AddNode( q1 );
            g.AddNode( q2 );

            g.Join( q1, q2 );

            int x = 0;
            double fke = 100;
            do {

                g.Compute(null);
                double ke = g.TotalKineticEnergy;

                double kediff = Math.Max( fke, ke ) - Math.Min( fke, ke );
                Console.WriteLine("kediff = {0}", kediff );

                if ( kediff < 0.001 ) break;

                if ( x++ > 1000 ) break;

                fke = ke;

            } while ( true );
        }
Beispiel #2
0
        public void ComputeRepulstion()
        {
            Node q1 = new Node(){ Charge = 2 };
            Node q2 = new Node(){ Charge = 2 };
            q2.Location.X = 10;

            // F = Ke*Q1*Q2 / r*2

            double r = Point.Distance( q1.Location, q2.Location );

            double f = ( Graph.CoulombConstant * q1.Charge * q2.Charge ) / Math.Pow( r , 2 );

            Assert.AreEqual( f, Graph.Repulsion( q1, q2 ) );
        }
Beispiel #3
0
        public static double SpringAttraction(Node a, Spring p)
        {
            if (!a.Links.Contains (p))
                throw new InvalidOperationException ("Node is not attached to this spring");

            double r = Point.Distance (a.Location , p.Other(a).Location);
            double x = r - p.NaturalLength;
            double F = (-1 * SpringConstant * x);

            return F;
        }
Beispiel #4
0
        public static double Repulsion(Node a, Node b)
        {
            double Q = a.Charge * b.Charge;
            double r = Point.Distance (a.Location, b.Location);
            double F = ( CoulombConstant * Q ) / Math.Pow( r, 2 );

            return F;
        }
Beispiel #5
0
        public Spring Join(Node a, Node b)
        {
            Spring p = new Spring () {
                NaturalLength = SpringNatualLength,
                NodeA = a,
                NodeB = b
            };

            a.Links.Add( p );
            b.Links.Add( p );

            springs.Add( p );
            return p;
        }
Beispiel #6
0
 public void AddNode(Node node)
 {
     foreach (var n in nodes) {
         if (n.Location.Equals (node.Location)) {
             throw new InvalidOperationException ("Another node already exists at this exact location ");
         }
     }
     nodes.Add (node);
 }
Beispiel #7
0
        public void Simple3NodeGraph()
        {
            Graph g = new Graph ();
            Node q1 = new Node ();
            Node q2 = new Node ();
            Node q3 = new Node ();

            q1.Location = new Point(){ X = 1, Y = 5, Z = 0 };
            q2.Location = new Point(){ X = 0, Y = -2, Z = 0 };
            q3.Location = new Point(){ X = -4, Y = 3, Z = 5 };

            g.AddNode( q1 );
            g.AddNode( q2 );
            g.AddNode( q3 );

            g.Join( q1, q3 );
            g.Join( q1, q2 );

            g.ComputeFull( 0.0001 , null );
        }