Code Monkey home page Code Monkey logo

orbitalmechanics's Introduction

OrbitalMechanics

An Actionscript 3 planetary physics simulator

Features

  • Calculates gravitational force
  • Simulates inelastic collisions
  • Provides example UI

Example

Here is an example body with an initial velocity being added to the system: ```actionscript var system:OrbitalMechanics = new OrbitalMechanics(); system.addBody(new Body(0, 50, 3, new Geovector(6, Math.PI))); system.x = 0; system.y = 0; stage.addChild(system); ```

Usage

The System

The simulation is a MovieClip-based object, which can be created like so: ```actionscript var system:OrbitalMechanics = new OrbitalMechanics(); system.x = 0; system.y = 0; stage.addChild(system); ``` Bodies can be added and removed from the system: ```actionscript system.addBody(b:Body); system.removeBody(b:Body); ```

The system can stop and start updating on ENTER_FRAME using the following functions:

system.pause();
system.resume();

The system is calculating on ENTER_FRAME by default when it is initialized.

Bodies

Bodies are initialized in the following way: ```actionscript var b:Body = new Body(x:Number, y:Number, mass:Number, velocity:Geovector); ```

Bodies have the following public properties:

velocity:Geovector
mass:Number //read-only
radius:Number //read-only

Geometric Vectors

Geometric vectors (class Geovector) are initialized like this: ```actionscript var v:Geovector = new Geovector(magnitude:Number, angle:Number); ``` All angles are in radians.

Geovectors can be added or subtracted from other geovectors:

v.add(v2:Geovector);
v.subtract(v2:Geovector);

Geovectors can be split into their components using their x and y functions:

v.x():Number
v.y():Number

Geovectors have the following public properties:

magnitude:Number
angle:Number

Math

Gravitational force is calculated using the formula F = (G * m1 * m2)/(d2), where G is the arbitrary number 100, masses are in arbitrrary units where mass = 1 is comparable to a small asteroid, and distance is measured in Flash units.

When two bodies collide (when the distance between them is less than the sum of their radii), they are replaced with a single body with their combined mass. The resulting body's velocity is found assuming it is a perfectly inelastic collision using the formula m1v1 + m2v2 = (m1 + m2)v'

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.