## Gravity Simulator v1.0

This project actually grew out of a demo I did for my students in Governor’s School, now it’s basically a zero-player video game (meaning, you set it up, and then watch it). It has a lot of cool features which I’ll try to go through here. Each frame solves the gravity differential equations describing the system using the Euler Method (aka, it just assumes it’s linear for a small interval). Presently it’s set to calculate 250 steps each frame. The model for gravity employed by this simulation is ∝ 1/r^2. Objects are non-corporeal (meaning they can freely pass through one another), however they are assumed to have a uniform density. Therefore when one object is inside another the force ∝r. Where r means the distance between the centers of the two objects. Basically, when an object is inside another the simulation assumes it feels gravity only from the shells that lie “bellow” it, so gravity will be zero at the center of any object. For more about this read up on Gauss’ Law for Gravity.

There’s an interactive method for creating a simulation from scratch, as well as a bunch of premade simulations that I wrote which are fun to watch. To place objects is a 3-step process. First you click where on the screen you want the object to start the simulation, next two buttons appear that will make the object larger or smaller, next you click anywhere else on the screen to set the object’s initial velocity vector. At any time you can click the lower righthand corner and stop placing objects and start the simulation, if an object is being placed when you do this it will be discarded.

At any time (except at the main menu) you can click the lower lefthand corner and abort back to the main menu. Your toggle choices are left as they were in this case.

Here’s the rundown on the “Toggle Options” you get:

## CoM Centering

By default the simulation is played in the “Center of Mass” frame, meaning that the center of the screen or the center of mass of the system. The Center of Mass is defined to be the point where the “weighted relative position” of the masses sums to zero. Put another way, were the simulation a rigid object this is the point at which the whole thing would balance. This can be turned off (but then if the objects fly off the screen that’s your problem).

## Object Paths

This records the last 100 frames’ positions for each object in the simulation, and displays a curve corresponding to lines joining them. For really small objects you kind of want this on, or else you won’t actually see what they’re doing.

## Orbit Projection

Enabling this option projects the NEXT 100 frames when placing an object. This is done by ACTUALLY running the simulation ahead, so it can be quite costly. This doesn’t really work effectively for more than about 12 object. The projection will appear on the step wherein you choose the object’s initial velocity.

## Manual Coloring

By default the color of an object is determined by its size in a way that is intended to be suggestive of the real solar system. Enabling this option produces a color wheel before the initial position step for a new object where you can click the color you want the new object to be. The color wheel was adapted from some code by Shanfan Huang whose website is here and whose OpenProcessing portfolio is here used under the terms of the GPL.

## A Simple (and fun to watch) Solar System

This is the third of my class demos to post on here, this one is a bit basic but it’s a lot of fun to watch. It was meant to build up the idea of an n-body simulation. These planets revolve around the “star” at the center, but in reality they’re just orbiting the (0,0) position. They are not “aware” of each other’s existence. Source code is here.

## Springs, Sproings, and Pendula

This is another simulation I wrote as a demonstration for my lab class. This simulator lets you play around with some pendula, springs, and a thing I call sproings. A sproing is like a spring, but instead of

$\vec{F} = -k\vec{r}$

its force law scales as

$\vec{F} = -k\vec{r}^2$

Where $\vec{r}$ means the vector from the equilibrium position to the location of the mass that’s bobbing around. Sproings are horrendously boring in their behavior, but their behavior isn’t easy to solve with differential equations, so it is really cool to be able to show their motion is sinusoidal just by numerically solving the differential equation (as we do here). Source code is available here.

## Downward Gravity Simulator

This is a demonstration applet I made for the lab class I TAed for at PA Governor’s School for the Sciences to illustrate both simulating gravitational/ballistic motion, and also solving differential equations numerically (although that topic is sort of implicit in the code here). It’s pretty straightforward to play with and the code is available here under GNU GPL.

It’s kind of a silly little toy, but I used this code to later build up an n-body simulator.

## Hi Everybody!

Hello world, this is my personal webpage, if you go to the About Me section can learn….all about me…besides that…

“The best things in life aren’t things” – fortune cookie.