Пример #1
0
 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));
                 }
             }
         }
     }
 }
Пример #2
0
 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));
         }
     }
 }