Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngraph.physics.simulator

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngraph.physics.simulator

Physics library for ngraph

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-5.1%
Maintainers
1
Weekly downloads
 
Created
Source

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" 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

Keywords

FAQs

Package last updated on 02 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc