calculateRepulsionForce method

Vector2 calculateRepulsionForce(
  1. Node other, {
  2. required double k,
})

Calculate the repulsive force following Coulomb's law.

The force is calculated based on the distance between the current Node and the other Node, and the required double value k.

Implementation

Vector2 calculateRepulsionForce(Node other, {required double k}) {
  final distance = position.distanceTo(other.position);
  final direction = (position - other.position).normalized();
  return direction * k * k / distance;
}