New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@gravity-simulator/gravity-resolver

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gravity-simulator/gravity-resolver

Resolves gravity for bodies, performing calculations on the gpu

  • 0.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-72.73%
Maintainers
1
Weekly downloads
 
Created
Source

Gravity Resolver

Provides two classes for performing gravity calculations in 2D.

Gravity Resolver

Given an array of bodies, parallelly performs gravity calculations between all bodies on GPU, and returns the array of bodies with updated position and velocity vectors

Barnes Hut Tree Resolver

Given an array of bodies and a quadtree of nodes with references to the bodies, parallelly performs gravity calculation approximation via the barnes hut algorithm, and returns the array of bodies with updated position and velocity vectors

Installation

npm install @gravity-simulator/gravity-resolver

Usage

Bodies should provide the following properties:

  • mass: number
  • positionX: number
  • positionY: number
  • velocityX: number
  • velocityY: number

Example usage - Gravity Resolver

const GravityResolver = require('@gravity-simulator/gravity-resolver').GravityResolver;

const resolver = new GravityResolver();

const bodies = [{mass: 100, positionX: 40, positionY: 120, velocityX: 0, velocityY: 0},
                {mass: 200, positionX: 80, positionY: 120, velocityX: 0, velocityY: 0},
                {mass: 50, positionX: 160, positionY: 40, velocityX: 0, velocityY: 0},
                {mass: 100, positionX: 160, positionY: 160, velocityX: 0, velocityY: 0}];

resolver.resolveNewPositions(bodies);

console.log(bodies) 
==> [
        {
            mass: 100,
            positionX: 40.132930755615234,
            positionY: 120.00064086914062,
            velocityX: 0.13292938470840454,
            velocityY: 0.00064300955273211
        },
        {
            mass: 200,
            positionX: 79.9514389038086,
            positionY: 120.0028305053711,
            velocityX: -0.048557523638010025,
            velocityY: 0.0028280343394726515
        },
        {
            mass: 50,
            positionX: 159.98495483398438,
            positionY: 40.020660400390625,
            velocityX: -0.015048785135149956,
            velocityY: 0.02065981552004814
        },
        {
            mass: 100,
            positionX: 159.97171020507812,
            positionY: 159.98336791992188,
            velocityX: -0.028289951384067535,
            velocityY: -0.016628986224532127
        }
    ]

Configuration

Both Resolvers accept an input to the constructor for a gravity constant (default = 1)

Considerations

Gravity Resolver is suitable for smaller numbers of bodies. For larger numbers of bodies, Barnes Hut Tree resolver should offer greater performance. To build the quadtree, use barnes-hut-tree-builder module https://www.npmjs.com/package/barnes-hut-tree-builder, using the buildToArray method.

This project is still in early development and further features for ease of use, as well as more extensive documentation will be coming in later versions.

Keywords

FAQs

Package last updated on 22 Jul 2020

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