ApplyForce() 공개 메소드

public ApplyForce ( AbstractVector force ) : void
force AbstractVector
리턴 void
예제 #1
0
        // TODO: change this for group only after node grouping
        // Coulombs Law explains what force
        // Force = (constant * | q1 * q2| )
        //         -------------------------
        //                distance^2
        protected void applyCoulombsLaw()
        {
            foreach (Node n1 in graph.nodes)
            {
                Point point1 = GetPoint(n1);
                foreach (Node n2 in graph.nodes)
                {
                    Point point2 = GetPoint(n2);
                    if (point1 != point2)
                    {
                        AbstractVector d         = point1.position - point2.position;
                        float          distance  = d.Magnitude() + 0.1f;
                        AbstractVector direction = d.Normalize();

                        if (n1.Pinned && n2.Pinned)
                        {
                            point1.ApplyForce(direction * 0.0f);
                            point2.ApplyForce(direction * 0.0f);
                        }
                        else if (n1.Pinned)
                        {
                            point1.ApplyForce(direction * 0.0f);
                            //point2.ApplyForce((direction * Repulsion) / (distance * distance * -1.0f));
                            point2.ApplyForce((direction * Repulsion) / (distance * -1.0f));
                        }
                        else if (n2.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()
        {
            foreach (Node n in graph.nodes)
            {
                Point point = GetPoint(n);
                if (!point.node.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));
                }
            }
        }