Code Monkey home page Code Monkey logo

ngraph.physics.simulator.v2's Introduction

Physics for ngraph

This is a physics module for ngraph. Its 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" layout system has kind of 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 simulator = require('ngraph.physics.simulator');
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.v2's People

Contributors

anvaka avatar nickolasmv avatar

Watchers

James Cloos avatar

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.