コード例 #1
0
        protected void applyHookesLaw()
        {
            foreach (Connection e in graph.Connections)
            {
                Spring         spring       = GetSpring(e);
                AbstractVector d            = spring.point2.position - spring.point1.position;
                float          displacement = spring.Length - d.Magnitude();
                AbstractVector direction    = d.Normalize();

                var pt1GridBox = graph.NodesWithGridBox[spring.point1.node];
                var pt2GridBox = graph.NodesWithGridBox[spring.point2.node];

                if (pt1GridBox.boxType == BoxType.Pinned && pt2GridBox.boxType == BoxType.Pinned)
                {
                    spring.point1.ApplyForce(direction * 0.0f);
                    spring.point2.ApplyForce(direction * 0.0f);
                }
                else if (pt1GridBox.boxType == BoxType.Pinned)
                {
                    spring.point1.ApplyForce(direction * 0.0f);
                    spring.point2.ApplyForce(direction * (spring.K * displacement));
                }
                else if (pt1GridBox.boxType == BoxType.Pinned)
                {
                    spring.point1.ApplyForce(direction * (spring.K * displacement * -1.0f));
                    spring.point2.ApplyForce(direction * 0.0f);
                }
                else
                {
                    spring.point1.ApplyForce(direction * (spring.K * displacement * -0.5f));
                    spring.point2.ApplyForce(direction * (spring.K * displacement * 0.5f));
                }
            }
        }
コード例 #2
0
        protected void attractToCentre()
        {
            foreach (var kv in graph.NodesWithGridBox)
            {
                Point point = GetPoint(kv);
                if (kv.Value.boxType != BoxType.Pinned)
                {
                    AbstractVector direction = point.position * -1.0f;
                    //point.ApplyForce(direction * ((float)Math.Sqrt((double)(Repulsion / 100.0f))));


                    float displacement = direction.Magnitude();
                    direction = direction.Normalize();
                    point.ApplyForce(direction * (Stiffness * displacement * 0.4f));
                }
            }
        }
コード例 #3
0
        // TODO: change this for group only after node grouping
        protected void applyCoulombsLaw()
        {
            foreach (var kv in graph.NodesWithGridBox)
            {
                Point point1 = GetPoint(kv);
                foreach (var kv2 in graph.NodesWithGridBox)
                {
                    Point point2 = GetPoint(kv2);
                    if (point1 != point2)
                    {
                        AbstractVector d         = point1.position - point2.position;
                        float          distance  = d.Magnitude() + 0.1f;
                        AbstractVector direction = d.Normalize();
                        if (kv.Value.boxType == BoxType.Pinned && kv2.Value.boxType == BoxType.Pinned)
                        {
                            point1.ApplyForce(direction * 0.0f);
                            point2.ApplyForce(direction * 0.0f);
                        }
                        else if (kv.Value.boxType == BoxType.Pinned)
                        {
                            point1.ApplyForce(direction * 0.0f);
                            //point2.ApplyForce((direction * Repulsion) / (distance * distance * -1.0f));
                            point2.ApplyForce((direction * Repulsion) / (distance * -1.0f));
                        }
                        else if (kv2.Value.boxType == BoxType.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));
                        }
                    }
                }
            }
        }