Orbit simulator programme, help?

import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as ptch import matplotlib.lines as lne import matplotlib.animation as ani

Constants

G = 6.673481010*-11 # Universal grav constant G=6.6734810x10-11 m3/kgs2 g = 9.81 # Gravity, g

Mass

massS = 1.98910*30 #kg

massS = 1000

massE = 5.97210*24 #kg

massE=1

Velocity

vel_earth = 460 #m/s

t=0

x=0 y=10

vY = 3.4 vX = 3.4

dt=60

def Grav(x,y,vX,vY): #x=0 #y=50 r = np.sqrt( x2 + y2 ) #distance from Sun (0,0) to Earth aX = -(GmassSmassE / abs(r)3)x #acceleration in x direction aY = -(GmassS*massE / abs(r)3)y #acceleration in y direction vY = vY + aYdt #updated Velocity with acc. in the y direction vX = vX + aXdt #updated Velocity with acc. in the x direction x = x + vXdt #updated position with vel. in the x direction y = y + vY*dt #updated position with vel. in the y direction return x,y,vX,vY

add np.array(x,y) once working.

positionE=(x,y)

def Orbit (i,delta,dt,glowlen): global x global y global vX global vY t=i*dt print i print t print x print y x,y,vX,vY=Grav(x,y,vX,vY) ax.cla() ax.plot(x,y, marker='o', ms=10, color='g') #ax.plot(0,0, marker='o', ms=100, color='y') plt.xlim(-1000,1000) #Grid dimensions plt.ylim(-1000,1000) return ax

fig = plt.figure() ax = fig.add_subplot(1, 1, 1)

anim = ani.FuncAnimation(fig, Orbit,fargs=(dt,0.05,1)) #(a,b,delta,0.05,1)) plt.show()

/r/learnpython Thread