* sum(n in adjacent, attract(n)) Returns norm(F)
*/
public Vector2D computeNodeImpulse() {
// Add a random force and the gravitational force
Vector2D resultForce = gravitionalForce().add(randomForce());
// Repulsive forces
for (SpringGraphNode otherNode : G.nodes) {
if (otherNode != this) {
resultForce = resultForce.add(repulsiveForce(otherNode));
}
}
// Attractive forces
for (SpringGraphNode otherNode : in) {
resultForce = resultForce.sub(this.attractiveForce(otherNode));
}
for (SpringGraphNode otherNode : out) {
resultForce = resultForce.sub(attractiveForce(otherNode));
}
// Repulsion of left and right wall
resultForce = resultForce.add(repulsiveForceWall(new Vector2D(0, y)));
resultForce = resultForce.add(repulsiveForceWall(new Vector2D(G.minSize.getX(), y)));
// Repulsion of top and bottom wall
resultForce = resultForce.add(repulsiveForceWall(new Vector2D(x, 0)));
resultForce = resultForce.add(repulsiveForceWall(new Vector2D(x, G.minSize.getY())));
// we only need the impulse
return resultForce.normalize();
}