这个更为绝佳:等质三体+行星(楽)import turtle
import math as ma
tstep=0.0002
def _angle(z):
if z.real>0:
return ma.atan(z.imag/z.real)
elif z.real<0:
return ma.atan(z.imag/z.real)+ma.pi
else:
if z.imag>=0:
return ma.pi/2
else:
return -ma.pi/2
mlist=[100000,100000,100000,1]
rlist=[0+60j,40+50j,-80-80j,0+0j]
vlist=[1+1j,0-5j,-5+2j,1-5j]
t_0,t_1,t_2,t_3=turtle.Turtle(),turtle.Turtle(),turtle.Turtle(),turtle.Turtle()
f=0
G=1
t_0.up()
t_1.up()
t_2.up()
t_3.up()
t_0.color("red")
t_1.color("green")
t_2.color("blue")
t_3.color("orange")
t_0.goto(rlist[0].real,rlist[0].imag)
t_1.goto(rlist[1].real,rlist[1].imag)
t_2.goto(rlist[2].real,rlist[2].imag)
t_3.goto(rlist[3].real,rlist[3].imag)
#t_0.down()
#t_1.down()
#t_2.down()
t_3.down()
def F(a,b):
f=G*mlist[a]*mlist[b]/abs(rlist[a]-rlist[b])
return f*ma.cos(_angle(rlist[b]-rlist[a]))+f*ma.sin(_angle(rlist[b]-rlist[a]))*1j
while True:
for i in range(50):
vlist[0]+=(F(0,1)+F(0,2)+F(0,3))/mlist[0]*tstep
vlist[1]+=(F(1,0)+F(1,2)+F(1,3))/mlist[1]*tstep
vlist[2]+=(F(2,0)+F(2,1)+F(2,3))/mlist[2]*tstep
vlist[3]+=(F(3,0)+F(3,1)+F(3,2))/mlist[3]*tstep
rlist[0]+=vlist[0]*tstep
rlist[1]+=vlist[1]*tstep
rlist[2]+=vlist[2]*tstep
rlist[3]+=vlist[3]*tstep
t_0.goto(rlist[0].real,rlist[0].imag)
t_1.goto(rlist[1].real,rlist[1].imag)
t_2.goto(rlist[2].real,rlist[2].imag)
t_3.goto(rlist[3].real,rlist[3].imag)
|