Exemple #1
0
 public Point(AbstractVector iPosition, AbstractVector iVelocity, AbstractVector iAcceleration, Node iNode)
 {
     position     = iPosition;
     node         = iNode;
     velocity     = iVelocity;
     acceleration = iAcceleration;
 }
Exemple #2
0
        private void ApplyHookesLaw()
        {
            foreach (var e in Graph.Edges)
            {
                Spring         spring       = GetSpring(e);
                AbstractVector d            = spring.Point2.Position - spring.Point1.Position;
                float          displacement = spring.Length - d.Magnitude();
                AbstractVector direction    = d.Normalize();

                if (spring.Point1.Node.Pinned && spring.Point2.Node.Pinned)
                {
                    spring.Point1.ApplyForce(direction * 0.0f);
                    spring.Point2.ApplyForce(direction * 0.0f);
                }
                else if (spring.Point1.Node.Pinned)
                {
                    spring.Point1.ApplyForce(direction * 0.0f);
                    spring.Point2.ApplyForce(direction * (spring.K * displacement));
                }
                else if (spring.Point2.Node.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));
                }
            }
        }
Exemple #3
0
        public override BoundingBox GetBoundingBox()
        {
            BoundingBox boundingBox = new BoundingBox();
            FDGVector2  bottomLeft  = FDGVector2.Identity().Multiply(BoundingBox.defaultBB * -1.0f) as FDGVector2;
            FDGVector2  topRight    = FDGVector2.Identity().Multiply(BoundingBox.defaultBB) as FDGVector2;

            foreach (Node n in graph.nodes)
            {
                FDGVector2 position = GetPoint(n).position as FDGVector2;

                if (position.x < bottomLeft.x)
                {
                    bottomLeft.x = position.x;
                }
                if (position.y < bottomLeft.y)
                {
                    bottomLeft.y = position.y;
                }
                if (position.x > topRight.x)
                {
                    topRight.x = position.x;
                }
                if (position.y > topRight.y)
                {
                    topRight.y = position.y;
                }
            }
            AbstractVector padding = (topRight - bottomLeft).Multiply(BoundingBox.defaultPadding);

            boundingBox.bottomLeftFront = bottomLeft.Subtract(padding);
            boundingBox.topRightBack    = topRight.Add(padding);
            return(boundingBox);
        }
Exemple #4
0
        protected void applyHookesLaw()
        {
            foreach (Edge e in graph.edges)
            {
                Spring         spring       = GetSpring(e);
                AbstractVector d            = spring.point2.position - spring.point1.position;
                float          displacement = spring.Length - d.Magnitude();
                AbstractVector direction    = d.Normalize();

                if (spring.point1.node.Pinned && spring.point2.node.Pinned)
                {
                    spring.point1.ApplyForce(direction * 0.0f);
                    spring.point2.ApplyForce(direction * 0.0f);
                }
                else if (spring.point1.node.Pinned)
                {
                    spring.point1.ApplyForce(direction * 0.0f);
                    spring.point2.ApplyForce(direction * (spring.K * displacement));
                }
                else if (spring.point2.node.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));
                }
            }
        }
Exemple #5
0
 public Point(AbstractVector iPosition, AbstractVector iVelocity, AbstractVector iAcceleration,Node iNode)
 {
     position=iPosition;
     node = iNode;
     velocity = iVelocity;
     acceleration = iAcceleration;
 }
Exemple #6
0
 protected override void drawNode(Node iNode, AbstractVector iPosition)
 {
     // Draw the given node according to given position
     Function f = controller.nodes [ulong.Parse (iNode.Data.label)] as Function;
     f.nx = iPosition.x;
     f.ny = iPosition.y;
     f.nz = iPosition.z;
 }
        public override AbstractVector Add(AbstractVector v2)
        {
            FDGVector2 v22 = v2 as FDGVector2;

            x = x + v22.x;
            y = y + v22.y;
            return(this);
        }
        public override AbstractVector Subtract(AbstractVector v2)
        {
            FDGVector2 v22 = v2 as FDGVector2;

            x = x - v22.x;
            y = y - v22.y;
            return(this);
        }
        public override AbstractVector Subtract(AbstractVector v2)
        {
            FDGVector3 v32 = v2 as FDGVector3;

            x = x - v32.x;
            y = y - v32.y;
            z = z - v32.z;
            return(this);
        }
Exemple #10
0
        public override AbstractVector Add(AbstractVector v2)
        {
            FDGVector2 v22 = v2 as FDGVector2;

            X = X + v22.X;
            Y = Y + v22.Y;

            return(this);
        }
        public override AbstractVector Add(AbstractVector v2)
        {
            FDGVector3 v32 = v2 as FDGVector3;

            x = x + v32.x;
            y = y + v32.y;
            z = z + v32.z;
            return(this);
        }
Exemple #12
0
        public override AbstractVector Subtract(AbstractVector v2)
        {
            FDGVector2 v22 = v2 as FDGVector2;

            X = X - v22.X;
            Y = Y - v22.Y;

            return(this);
        }
Exemple #13
0
        public override AbstractVector Add(AbstractVector v2)
        {
            FDGVector3 v32 = v2 as FDGVector3;

            X = X + v32.X;
            Y = Y + v32.Y;
            Z = Z + v32.Z;

            return(this);
        }
Exemple #14
0
        public override AbstractVector Subtract(AbstractVector v2)
        {
            FDGVector3 v32 = v2 as FDGVector3;

            X = X - v32.X;
            Y = Y - v32.Y;
            Z = Z - v32.Z;

            return(this);
        }
Exemple #15
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));
                }
            }
        }
Exemple #16
0
        private void AttractToCentre()
        {
            foreach (var n in Graph.Nodes)
            {
                Particle point = GetParticle(n);
                if (point.Node.Pinned)
                {
                    continue;
                }

                AbstractVector direction    = point.Position * -1.0f;
                float          displacement = direction.Magnitude();
                direction = direction.Normalize();
                point.ApplyForce(direction * (Stiffness * displacement * 0.4f));
            }
        }
Exemple #17
0
        public NearestPoint Nearest(AbstractVector position)
        {
            NearestPoint min = new NearestPoint();

            foreach (Node n in graph.nodes)
            {
                Point point    = GetPoint(n);
                float distance = (point.position - position).Magnitude();
                if (min.distance == null || distance < min.distance)
                {
                    min.node     = n;
                    min.point    = point;
                    min.distance = distance;
                }
            }
            return(min);
        }
Exemple #18
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));
                        }
                    }
                }
            }
        }
Exemple #19
0
        // TODO: change this for group only after node grouping
        private void ApplyCoulombsLaw()
        {
            foreach (var n1 in Graph.Nodes)
            {
                Particle point1 = GetParticle(n1);
                foreach (var n2 in Graph.Nodes)
                {
                    Particle point2 = GetParticle(n2);
                    if (point1 == point2)
                    {
                        continue;
                    }

                    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 * -1.0f));
                    }
                    else if (n2.Pinned)
                    {
                        point1.ApplyForce((direction * Repulsion) / (distance));
                        point2.ApplyForce(direction * 0.0f);
                    }
                    else
                    {
                        point1.ApplyForce((direction * Repulsion) / (distance * 0.5f));
                        point2.ApplyForce((direction * Repulsion) / (distance * -0.5f));
                    }
                }
            }
        }
 public abstract AbstractVector Subtract(AbstractVector v2);
 public abstract AbstractVector Add(AbstractVector v2);
 protected override void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
 {
     //TODO: Change positions of line
     
     form.DrawLine(iEdge,iPosition1,iPosition2);
 }
Exemple #23
0
 protected override void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
 {
     // Draw the given edge according to given positions
 }
Exemple #24
0
 public override AbstractVector Add(AbstractVector v2)
 {
     FDGVector3 v32 = v2 as FDGVector3;
     x = x + v32.x;
     y = y + v32.y;
     z = z + v32.z;
     return this;
 }
Exemple #25
0
 public override AbstractVector Subtract(AbstractVector v2)
 {
     FDGVector3 v32 = v2 as FDGVector3;
     x = x - v32.x;
     y = y - v32.y;
     z = z - v32.z;
     return this;
 }
 protected abstract void drawNode(Node iNode, AbstractVector iPosition);
 public void DrawBox(Node iNode, AbstractVector iPosition)
 {
     Pair<int, int> pos = GraphToScreen(iPosition as FDGVector2);
     m_fdgBoxes[iNode].Set(pos.first, pos.second);
     m_fdgBoxes[iNode].DrawBox(paper);
 }
Exemple #28
0
 protected abstract void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2);
Exemple #29
0
 public abstract AbstractVector Add(AbstractVector v2);
Exemple #30
0
 public override AbstractVector Subtract(AbstractVector v2)
 {
     FDGVector2 v22 = v2 as FDGVector2;
     x=x-v22.x;
     y=y-v22.y;
     return this;
 }
Exemple #31
0
 protected abstract void drawNode(Node iNode, AbstractVector iPosition);
Exemple #32
0
 public void ApplyForce(AbstractVector force)
 {
     acceleration.Add(force/mass);
 }
Exemple #33
0
 public override AbstractVector Add(AbstractVector v2)
 {
     FDGVector2 v22 = v2 as FDGVector2;
     x= x+v22.x;
     y=y+v22.y;
     return this;
 }
 protected override void drawNode(Node iNode, AbstractVector iPosition)
 {
     //TODO: Change positions of line
     form.DrawBox(iNode,iPosition);
 }
Exemple #35
0
 public abstract AbstractVector Subtract(AbstractVector v2);
 protected abstract void drawEdge(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2);
Exemple #37
0
 public void ApplyForce(AbstractVector force)
 {
     acceleration.Add(force / mass);
 }
 public void DrawLine(Edge iEdge, AbstractVector iPosition1, AbstractVector iPosition2)
 {
     Pair<int, int> pos1 = GraphToScreen(iPosition1 as FDGVector2);
     Pair<int, int> pos2 = GraphToScreen(iPosition2 as FDGVector2);
     m_fdgLines[iEdge].Set(pos1.first, pos1.second, pos2.first, pos2.second);
     m_fdgLines[iEdge].DrawLine(paper);
     
 }