from turtle import *
from math import *
M_center=100000
G=1
tstep=0.1/20
list_size=4
mlist=[10,10,10,10]
rlist=[100+100j,100+100j,100+100j,100+100j]
vlist=[10-20j,-10+20j,5+15j,-5-15j]
tlist=[Turtle(),Turtle(),Turtle(),Turtle()]
for i in range(list_size):
tlist[i].speed(1000)
tlist[i].up()
tlist[i].goto(rlist[i].real,rlist[i].imag)
tlist[i].down()
def _angle(z):
if z.real>0:
return atan(z.imag/z.real)
elif z.real<0:
return atan(z.imag/z.real)+pi
else:
if z.imag>=0:
return pi/2
else:
return -pi/2
def _F(t_n):
# |F|=G*M_center*mlist[n]/(abs(rlist[n])**2)
# return : |F|*cos(_angle(rlist[n]))+|F|*sin(_angle(rlist[n]))*1j
return -G*M_center*mlist[t_n]/(abs(rlist[t_n])**2)*cos(_angle(rlist[t_n]))-G*M_center*mlist[t_n]/(abs(rlist[t_n])**2)*sin(_angle(rlist[t_n]))*1j
# main
while True:
for i in range(20):
for j in range(list_size):
rlist[j]+=vlist[j]*tstep
tlist[j].goto(rlist[j].real,rlist[j].imag)
vlist[j]+=_F(j)/mlist[j]*tstep
|