-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflyby.py
108 lines (80 loc) · 3.44 KB
/
flyby.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from celestialBodies import planet, spaceProbe
from data import *
from math import sqrt
start = "2021-11-22"
# venusEncounter = "2022-04-04"
sun = planet("Sun", 10, Ms, start=start)
venus = planet("Venus", 299, 8*Mv, start=start)
earth = planet("Earth", 399, Me, start=start)
mars = planet("Mars", 499, Mm, start=start)
earth.z = [0 for i in range(len(earth.z))]
earth.vz = [0 for i in range(len(earth.vz))]
venus.z = [0 for i in range(len(venus.z))]
venus.vz = [0 for i in range(len(venus.vz))]
vCurrent = sqrt((earth.vx[0]/daysec)**2 + (earth.vy[0]/daysec)**2 + (earth.vz[0]/daysec)**2)
# vDesired = vCurrent - 4.5E3
#3#3 -> slightly larger orbit
#3.1825E3 -> smaller orbit, significant change
vDesired = vCurrent + 4511
vPercent = vDesired/vCurrent
print(vCurrent)
print(vDesired)
print(vPercent)
probe = spaceProbe(30, sun, venus, earth, mars, daysec, vPercent)
# animation ###########################################################################################################
import matplotlib.pyplot as plt
from matplotlib import animation
import matplotlib
matplotlib.rcParams['animation.embed_limit'] = 2**128
matplotlib.use("TkAgg") # for mac
from IPython.display import HTML
fig, ax = plt.subplots(figsize=(10,10))
ax.set_aspect('equal')
ax.grid()
line_a, = ax.plot([],[],'-g',lw=1)
point_a, = ax.plot([AU], [0], marker="o", markersize=4, markeredgecolor="brown", markerfacecolor="brown")
text_a = ax.text(AU,0,'Venus')
line_b, = ax.plot([],[],'-g',lw=1)
point_b, = ax.plot([1.5*AU], [0], marker="o", markersize=3, markeredgecolor="blue", markerfacecolor="blue")
text_b = ax.text(1.666*AU,0,'Earth')
line_c, = ax.plot([],[],'-g',lw=1)
point_c, = ax.plot([2*AU], [0], marker="o", markersize=2, markeredgecolor="red", markerfacecolor="red")
text_c = ax.text(2*AU,0,'Mars')
line_d, = ax.plot([],[],'-g',lw=1)
point_d, = ax.plot([2*AU], [0], marker="o", markersize=2, markeredgecolor="black", markerfacecolor="black")
text_d = ax.text(2*AU,0,'Space Probe')
point_e = ax.plot([0], [0], marker="o", markersize=8, markeredgecolor="yellow", markerfacecolor="yellow")
text_e = ax.text(0,0,"Sun")
text_date = ax.text(-2.5*1E11, 2.4*1E11, earth.start)
axdata,aydata = [],[] # venus track
bxdata,bydata = [],[] # earth track
cxdata,cydata = [],[] # mars track
dxdata,dydata = [],[] # space probe track
def update(i):
axdata.append(venus.x[i])
aydata.append(venus.y[i])
bxdata.append(earth.x[i])
bydata.append(earth.y[i])
cxdata.append(mars.x[i])
cydata.append(mars.y[i])
dxdata.append(probe.xlist[i])
dydata.append(probe.ylist[i])
line_a.set_data(axdata,aydata)
point_a.set_data(venus.x[i],venus.y[i])
text_a.set_position((venus.x[i],venus.y[i]))
line_b.set_data(bxdata,bydata)
point_b.set_data(earth.x[i],earth.y[i])
text_b.set_position((earth.x[i],earth.y[i]))
line_c.set_data(cxdata,cydata)
point_c.set_data(mars.x[i],mars.y[i])
text_c.set_position((mars.x[i],mars.y[i]))
line_d.set_data(dxdata,dydata)
point_d.set_data(probe.xlist[i],probe.ylist[i])
text_d.set_position((probe.xlist[i],probe.ylist[i]))
ax.axis('equal')
ax.set_xlim(-2*AU,2*AU)
ax.set_ylim(-2*AU,2*AU)
text_date.set_text(earth.d[i])
return line_a,point_a,text_a,line_b,point_b,text_b,line_c,point_c,text_c,line_d,point_d,text_d,text_date
anim = animation.FuncAnimation(fig,func=update,frames=len(earth.x),interval=10,blit=True)
plt.show()