Skip to content

Instantly share code, notes, and snippets.

@certik
Created January 2, 2012 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certik/1551827 to your computer and use it in GitHub Desktop.
Save certik/1551827 to your computer and use it in GitHub Desktop.
Trajectory
from math import pi, sin, cos
from numpy import array, vstack
from numpy.linalg import norm
from pylab import plot, savefig
R = 10.
M = 1.
G = 1.
phi = 30 * 180. / pi
v0_magnitude = 0.1
r = array([0, 0, R])
v = v0_magnitude * array([cos(pi), 0, sin(pi)])
trajectory = []
dt = 0.1
t = 0
while t < 100:
trajectory.append(r.copy())
a = -G * M * r / norm(r)**3
v += a * dt
r += v * dt
t += dt
trajectory = vstack(trajectory)
plot(trajectory[:, 0], trajectory[:, 2])
savefig("trajectory.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment