Exemple #1
0
 public Node()
 {
     NodeId = Guid.NewGuid ();
     links = new List<Spring> ();
     Location = new Point ();
     Charge = 1;
     Mass = 0.1;
     Velocity = new Vector3D ();
     NetForce = new Vector3D ();
 }
Exemple #2
0
        // compute one step
        public void Compute( Action<Node> callback )
        {
            totalKE = 0.0;
            foreach (var a in Nodes) {
                // calculate repulsive forces
                a.NetForce = new Vector3D ();
                foreach (var b in Nodes) {
                    if (!b.Equals (a)) {
                        a.NetForce += (a.Location - b.Location).UnitVector * Repulsion (a, b);
                //		Console.WriteLine ("repulsion {0}", Repulsion (a, b));
                    }
                }

                // calculate spring forces
                foreach (var s in a.Links) {
                    a.NetForce += (a.Location - s.Other (a).Location).UnitVector * SpringAttraction (a, s);
                //	Console.WriteLine ("attraction {0}", SpringAttraction (a, s));
                }
            }

            // move and calculate KE
            foreach (var x in Nodes) {

                Vector3D vel = new Vector3D(){
                    X = x.NetForce.X * ComputeTimeStep * Damping,
                    Y = x.NetForce.Y * ComputeTimeStep * Damping,
                    Z = x.NetForce.Z * ComputeTimeStep * Damping
                };

                x.Location += new Point(){
                    X = vel.X * ComputeTimeStep,
                    Y = vel.Y * ComputeTimeStep,
                    Z = vel.Z * ComputeTimeStep
                };
                if ( x.Location.X < minX ) minX = x.Location.X;
                if ( x.Location.Y < minY ) minY = x.Location.Y;
                if ( x.Location.X > maxX ) maxX = x.Location.X;
                if ( x.Location.Y > maxY ) maxY = x.Location.Y;

                totalKE += x.Mass * Math.Pow( vel.Length , 2 );

                if ( callback != null ){
                    callback( x );
                }
            }
        }