Skip to content

A basic three-body simulation written in Rust. Used macroquad for graphics.

License

Notifications You must be signed in to change notification settings

manorajesh/threebody

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

threebody

A basic three-body simulation written in Rust. Used macroquad for graphics.

How

Each Body struct is initialized with position, velocity, acceleration, mass, and force (there are some other values but those are not as relevant).

On each update, the force between two bodies is calculated with Newton's Universal Law of Gravitation: $$F = G \frac{m_1 m_2}{r^2}$$ Since this is a 2-dimensional simulation, the resultant force $F$ is multiplied by the $\Delta x$ and $\Delta y$ to get the $x$ and $y$ components of the force respectively. Each force acting on the body should be summed: $$F_{total} = \sum_{j \neq i} F$$

Then, $F=ma$ is used to solve for $a$ or accelration. Rewriting the equation: $a = \frac{F}{m}$

From there, basic kinematics equations use dt or $\Delta t$ to solve for an updated velocity component and position component: $$v = v_i + at$$ $$p = p_i + vt$$

Why

I recently watched the 3 Body Problem show.

About

A basic three-body simulation written in Rust. Used macroquad for graphics.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages