Code Monkey home page Code Monkey logo

ngraph.physics.simulator's Introduction

Physics for ngraph

This was a physics module for ngraph.forcelayout.

With time this module was merged into ngraph.forcelayout and this package is no longer used.

Below is the rest of the readme file, kept for historical reasons.

Old readme

The module's primary focus is to serve force based graph layout, thus it manages a naïve system of bodies and springs.

Simulator calculates forces acting on each body and then deduces their position via Newton's law. There are three major forces in the system:

  1. Spring force keeps connected nodes together via Hooke's law
  2. Each body repels each other via Coulomb's law
  3. To guarantee we get to "stable" state the system has a drag force which slows entire simulation down.

Body forces are calculated in n*lg(n) time with help of Barnes-Hut algorithm implemented in quadtree module. Euler method is then used to solve ordinary differential equation of Newton's law and get position of bodies.

build status

quickstart

var physics = require('ngraph.physics.primitives');
var body1 = new physics.Body(0, 0);
var body2 = new physics.Body(1, 0);

var createSimulator = require('ngraph.physics.simulator');
var simulator = createSimulator();
simulator.addBody(body1);
simulator.addBody(body2);

simulator.step();

This will move apart two bodies.

For more advanced use cases, please look inside index.js, which includes documentation for public API and describes engine configuration properties.

install

With npm do:

npm install ngraph.physics.simulator

todo

I spent countless hours trying to optimize performance of this module but it's not perfect. Ideally I'd love to use native arrays to simulate physics. Eventually this will allow to calculate forces on video card or via webworkers.

license

MIT

ngraph.physics.simulator's People

Contributors

anvaka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ngraph.physics.simulator's Issues

"centering" force ?

I have a disconnected graph. I use forcelayout3D.
Currently my different clusters repel each others and move away indefinitely...
Of course I need my nodes not to overlap, so repels is needed.
But when the clusters are in distinct positions, they should stop to move, no need for the node to run far away...
Is there a way to fix that ?

Dynamically update Spring Length

I have dynamically changing connectionStrength (as per customLinkLength demo), and need to propagate the change to the physics engine. Spring Transform seems to only set the length initially.

Is there a preferred way to update the spring lengths dynamically?

Creating new forces

Hi!

I have following use case: some nodes need to be presented on the left/right/top/bottom of another, i.e. I need to apply some constant force to some groups of nodes. E.g. so some node will always happen to be above any other connected node rather than in random direction.

Is it possible to add new kinds of forces to simulation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.