Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterative-Relaxation in d3.forceLink #8

Open
gvarnavi opened this issue May 2, 2021 · 1 comment
Open

Iterative-Relaxation in d3.forceLink #8

gvarnavi opened this issue May 2, 2021 · 1 comment

Comments

@gvarnavi
Copy link

gvarnavi commented May 2, 2021

Wasn't too sure where to post this, but this repo seems to curate d3-force plugins for use in (perhaps) unusual use-cases, like physical simulations - so figured I'd alert users to energy-conservation in d3-force.

In particular, the Pendulum example asks:

Ok, I'm confused. Why isn't energy conserved and does the pendulum eventually stop?

Similarly, the Newton's Cradle example also 'thermalizes' albeit both explicitly setting:

d3.forceSimulation()
	.alphaDecay(0)
	.velocityDecay(0)

The issue is that d3.forceLink actually performs iterative relaxation. The offending lines in the source code are:

        x = target.x + target.vx - source.x - source.vx || jiggle(random);
        y = target.y + target.vy - source.y - source.vy || jiggle(random);

Note the link distance is specified by 'peeking ahead' to the anticipated position of the node ⟨x + vx,y + vy⟩.

This notebook further explains the issue using examples, and suggests two alternatives.

@vasturiano
Copy link
Owner

@gvarnavi this is awesome research, great work! I think it's well worth to post this on the https://github.com/d3/d3-force repo for broader visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants