The Force Directed Layout sample demonstrates a way to position nodes by pretending they have physical effects on each other. Each node has a mass and an electrical charge and each link acts as a spring.

Modifying one of the properties will automatically perform another layout using the new property value, because the values of the ForceDirectedLayout properties are data-bound to the controls in the sample.

The algorithm moves each node in the direction of the net force on it in each iteration. The more iterations, the closer the nodes will be to reaching equilibrium, if it is possible with the current setup. The motion of the nodes can be customized by setting the GravitationalMass and ElectricalCharge. The forces of the links can be customized by setting SpringStiffness and (nominal) SpringLength. When no node moves by more than the Epsilon distance, or when the number of iterations reaches MaxIterations, the layout stops. Nodes that are farther away than InfinityDistance are assumed not to have any gravitational or electrical effect on each other.