Skip to content

Instantly share code, notes, and snippets.

@saethlin
Created May 19, 2017 22:20
Show Gist options
  • Save saethlin/6526cb9bb855a85b85ac5c95d0e543a3 to your computer and use it in GitHub Desktop.
Save saethlin/6526cb9bb855a85b85ac5c95d0e543a3 to your computer and use it in GitHub Desktop.
Point:
x, y, z f64
Particle:
position, velocity, acceleration Point
mass f64
particles = SoA(Particle, 100)
particles.position = random(0.03, 0.03)
particles.mass = 1e-6
time_step = 0.08
time_limit = 365.25
time = 0.0
while time < time_limit using particles:
position += velocity * time_step/2
for this, others in iter_pairs(particles):
d = this.position - others.position
r = sqrt(d.x^2 + d.y^2 + d.z^2)
this.acceleration = -G/r^3 * others.mass * d
time += time_step
velocity += acceleration * time_step
position += velocity * time_step/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment