npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gravity-simulator/gravity-resolver

v0.0.10

Published

Resolves gravity for bodies, performing calculations on the gpu

Downloads

7

Readme

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.