protected override void drawNode(City iNode, AbstractVector iPosition) { Tuple <int, int> pos = GraphToScreen(iPosition as FDGVector2); Boxes[iNode].Set(pos.Item1, pos.Item2); Boxes[iNode].DrawBox(Paper, iNode); }
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 (var kv in graph.NodesWithGridBox) { FDGVector2 position = GetPoint(kv).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); }
public Point(AbstractVector iPosition, AbstractVector iVelocity, AbstractVector iAcceleration, City iNode) { position = iPosition; node = iNode; velocity = iVelocity; acceleration = iAcceleration; }
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)); } } }
protected override void drawEdge(Connection iEdge, AbstractVector iPosition1, AbstractVector iPosition2) { Tuple <int, int> pos1 = GraphToScreen(iPosition1 as FDGVector2); Tuple <int, int> pos2 = GraphToScreen(iPosition2 as FDGVector2); Lines[iEdge].Set(pos1.Item1, pos1.Item2, pos2.Item1, pos2.Item2); Lines[iEdge].DrawLine(Paper, iEdge); }
public override AbstractVector Subtract(AbstractVector v2) { FDGVector2 v22 = v2 as FDGVector2; x = x - v22.x; y = y - v22.y; return(this); }
public override AbstractVector Add(AbstractVector v2) { FDGVector2 v22 = v2 as FDGVector2; x = x + v22.x; y = y + v22.y; return(this); }
public NearestPoint Nearest(AbstractVector position) { NearestPoint min = new NearestPoint(); foreach (var kv in graph.NodesWithGridBox) { Point point = GetPoint(kv); float distance = (point.position - position).Magnitude(); if (min.distance == null || distance < min.distance) { min.node = kv.Key; min.point = point; min.distance = distance; } } return(min); }
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)); } } }
// 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)); } } } } }
public GridBox(int iX, int iY, BoxType iType, string label) { InitialPosition = FDGVector2.Random() as FDGVector2; this.x = iX; this.y = iY; this.boxType = iType; switch (iType) { case BoxType.Normal: brush = new SolidBrush(Color.Black); break; case BoxType.Pinned: brush = new SolidBrush(Color.Red); break; } width = 18; height = 18; boxRec = new Rectangle(x, y, width, height); Label = label; }
protected abstract void drawNode(City iNode, AbstractVector iPosition);
protected abstract void drawEdge(Connection iEdge, AbstractVector iPosition1, AbstractVector iPosition2);
public void ApplyForce(AbstractVector force) { acceleration.Add(force); }
public abstract AbstractVector Subtract(AbstractVector v2);
public abstract AbstractVector Add(AbstractVector v2);