protected void updatePosition(float timeStep)
 {
     foreach (var n in Graph.Nodes)
     {
         PointFD point = GetPoint(n);
         point.Position += point.Velocity * timeStep * 0.01f;
     }
 }
Example #2
0
 public bool Equals(PointFD p)
 {
     if ((object)p == null)
     {
         return(false);
     }
     return(Position == p.Position);
 }
 protected void updateVelocity(float timeStep)
 {
     foreach (var n in Graph.Nodes)
     {
         PointFD point = GetPoint(n);
         point.Velocity    += point.Acceleration * timeStep;
         point.Velocity    *= Damping;
         point.Acceleration = Vector3.zero;
     }
 }
        protected float getTotalEnergy()
        {
            float energy = 0.0f;

            foreach (var n in Graph.Nodes)
            {
                PointFD point = GetPoint(n);
                float   speed = point.Velocity.magnitude;
                energy += 0.5f * point.Mass * speed * speed;
            }
            return(energy);
        }
Example #5
0
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            PointFD p = obj as PointFD;

            if ((System.Object)p == null)
            {
                return(false);
            }
            return(Position == p.Position);
        }
        //gives a dict of calculated data, to return to presenter
        public Dictionary <int, Vector3> ApplyCalculation()
        {
            Dictionary <int, Vector3> dict = new Dictionary <int, Vector3>();

            foreach (var n in Graph.Nodes)
            {
                PointFD point = GetPoint(n);
                dict.Add(point.Node.Uid, point.Position);
                //model should be updated here.
                //point.Node.PosX = point.Position.x;
                //point.Node.PosY = point.Position.y;
                //point.Node.PosZ = point.Position.z;
            }
            return(dict);
        }
 protected void applyCoulombsLaw(bool twoD = false)
 {
     foreach (var n1 in Graph.Nodes)
     {
         PointFD point1 = GetPoint(n1);
         foreach (var n2 in Graph.Nodes)
         {
             PointFD point2 = GetPoint(n2);
             if (point1 != point2)
             {
                 Vector3 d         = point1.Position - point2.Position;
                 float   distance  = d.magnitude + 0.1f;
                 Vector3 direction = d.normalized;
                 if (twoD)
                 {
                     direction.z = 0;
                 }
                 if (point1.Pinned && point2.Pinned)
                 {
                     point1.ApplyForce(direction * 0.0f);
                     point2.ApplyForce(direction * 0.0f);
                 }
                 else if (point1.Pinned)
                 {
                     point1.ApplyForce(direction * 0.0f);
                     //point2.ApplyForce((direction * Repulsion) / (distance * distance * -1.0f));
                     point2.ApplyForce((direction * Repulsion) / (distance * -1.0f));
                 }
                 else if (point2.Pinned)
                 {
                     //point1.ApplyForce((direction * Repulsion) / (distance * distance));
                     point1.ApplyForce((direction * Repulsion) / (distance));
                     point2.ApplyForce(direction * 0.0f);
                 }
                 else
                 {
                     //                             point1.ApplyForce((direction * Repulsion) / (distance * distance * 0.5f));
                     //                             point2.ApplyForce((direction * Repulsion) / (distance * distance * -0.5f));
                     point1.ApplyForce((direction * Repulsion) / (distance * 0.5f));
                     point2.ApplyForce((direction * Repulsion) / (distance * -0.5f));
                 }
             }
         }
     }
 }
 protected void attractToCentre(bool twoD = false)
 {
     foreach (var n in Graph.Nodes)
     {
         PointFD point        = GetPoint(n);
         Vector3 direction    = point.Position * -1.0f;
         float   displacement = direction.magnitude;
         direction = direction.normalized;
         if (twoD)
         {
             direction.z = 0;
         }
         if (!point.Pinned)
         {
             point.ApplyForce(direction * (Stiffness * displacement * 0.4f));
         }
     }
 }
        public void UpdatePositionInteracted(INode node, Vector3 position)
        {
            PointFD point = GetPoint(node);

            point.Position = position;
        }
        //pin a node, so now physics get applied
        public void PinNode(INode node, bool pin)
        {
            PointFD point = GetPoint(node);

            point.Pinned = pin;
        }