NodeNetwork icon indicating copy to clipboard operation
NodeNetwork copied to clipboard

Modification to physics based layouter

Open KayakSnail opened this issue 4 years ago • 5 comments

I notice that your repulsion force is proportional to 1/Distance. this is causing unconnected nodes to get ejected from a local group quite drastically. I would propose increasing the repulsion coefficent slightly and making the force proportional to 1/Distance^2 (similar to how gravity attracts). you cold then increase the friction component so that nodes slow down faster.

KayakSnail avatar Jul 25 '19 14:07 KayakSnail

Do you have a set of parameters that you would recommend? I've played around with it a bit, but can't find a setup that works very well. (Nodes still fly off when unconnected) Might be caused by a bug somewhere, since intuitively the friction should stop them sometime, but increasing friction has barely any impact.

Wouterdek avatar Jul 26 '19 14:07 Wouterdek

Unfortunately I've not been able to compile the code to test (let's not solve that here).

Looking over what you have written I can't see anything obviously wrong. I would set up a very simple simulation with 2 unconnected nodes (one fixed position) and see at what distance friction overcomes reupulsion. It may be necessary to have repulsion fall off more rapidly, which will require smaller spring constant once connected.

KayakSnail avatar Jul 29 '19 07:07 KayakSnail

I've finally managed to find some time to take a look at this and to get it working.

I have a couple of proposed changes (locally) but I'm not quite sure how to create a pull request for it. Is this a setting on your end or am I doing something wrong my end I wonder.

In brief:

  1. I've changed the Repulsion section to be based on an inverse gravity model (F=Gm1m2/r^2)
  2. There was a small bug in the friction section which was causing nodes to never stop moving (Friction was being set to the minimum of the Kinetic and the Repulsion+Spring values). Presumably this was to stop the Friction component from making the node move in the opposite direction?
  3. Removed the FrictionVector normalisation. Now the friction is proportional to the nodes velocity such that very fast nodes slow down and very slow nodes don't suddenly change direction (see 2. above)

KayakSnail avatar Sep 17 '19 10:09 KayakSnail

I fixed item 2 in commit aa35e0b, thanks for that. The other two suggestions seem to produce unstable results for me, for example when piling nodes on top of eachother. However, in my limited testing it seems like it already works pretty good by just fixing the friction?

Wouterdek avatar Sep 21 '19 16:09 Wouterdek

Fix worked to an extent for me. Now nodes don't ping off into the distance. However, nodes do now 'jitter' when the friction force is larger than the repulsion force and the node is nearly at rest. I.e. the friction component is causing a node to accelerate in the opposite direction. I would still reccomend removing the normalisation so that very slow moving nodes don't suddenly change direction due to friction forces alone.

KayakSnail avatar Oct 11 '19 12:10 KayakSnail