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)); } } }
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)); } } }
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)); } }
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)); } } }
// 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)); } } } } }
// 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)); } } } }