Created
May 19, 2017 22:20
-
-
Save saethlin/6526cb9bb855a85b85ac5c95d0e543a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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