Układ Słoneczny
Symulacja Układu Słonecznego
Uklad_Sloneczny.py
Idź do dokumentacji tego pliku.
1 
8 
9 from visual import*
10 from visual.graph import*
11 from visual.materials import texture
12 
13 
14 scene = display (x = 650, title = "Uklad Sloneczny", width = 1280, height = 1024, range = (5000,5000,25000), center = (0,0,0))
15 scene.autoscale = True
16 
17 
18 sun = sphere(pos=(0,0,0), radius=586, material = materials.emissive, color=color.yellow)
19 
20 mercury = sphere(pos=(1000.,0,0), radius=2.1, material = materials.wood, color=color.red)
21 mercury.trail = curve(color=mercury.color)
22 mercury.velocity = vector (0,0,117)
23 
24 venus = sphere(pos = (1862.414,0,0),radius=5.1, material = materials.wood, color=color.orange)
25 venus.trail = curve(color=venus.color)
26 venus.velocity = vector (0,0,85.53)
27 
28 earth = sphere(pos = (2586.241,0,0), radius = 5.4, material = materials.earth)#, color = color.yellow)
29 earth.trail = curve(color=color.blue)
30 earth.velocity = vector (0,0,72.75)
31 
32 moon = sphere(pos = (2586.241+6.552,0,0), radius=1.5, material = materials.rough, color=color.white)
33 moon.trail = curve(color=moon.color)
34 moon.velocitylocal = vector(0,0,2.44)
35 moon.velocityglobal = earth.velocity + moon.velocitylocal
36 
37 mars = sphere(pos=(3931.206,0,0), radius=2.9, material = materials.wood, color=color.green)
38 mars.trail = curve(color=mars.color)
39 mars.velocity = vector (0,0,59)
40 
41 jupiter = sphere(pos=(13413.759,0,0), radius=180.4, material = materials.marble, color=color.cyan)
42 jupiter.trail = curve(color=jupiter.color)
43 jupiter.velocity = vector(0,0,31.95)
44 
45 saturn = sphere(pos=(24137.586,0,0), radius=50.7, material = materials.marble, color=color.yellow)
46 saturn.trail = curve(color=saturn.color)
47 saturn.velocity = vector (0,0,23.6)
48 
49 uranus = sphere(pos=(50000.,0,0), radius=21.5, material = materials.wood, color=color.magenta)
50 uranus.trail = curve(color=uranus.color)
51 uranus.velocity = vector(0,0,16.71)
52 
53 neptune = sphere(pos=(77586.241,0,0), radius = 20.9, material = materials.wood, color=color.red)
54 neptune.trail = curve(color=neptune.color)
55 neptune.velocity = vector(0,0,13.27)
56 
57 pluto = sphere(pos=(101724.828,0,0),radius=1, material = materials.marble, color=color.orange)
58 pluto.trail = curve(color=pluto.color)
59 pluto.velocity = vector (0,0,11.55)
60 
61 
62 G = -6.7*10**-4
63 #masy wszystkich obiektow skala 1
64 m_sun = 2*10**10
65 m_mercury = 3.29*10**3
66 m_venus = 4.87*10**4
67 m_earth = 6.0*10**4
68 m_moon = 7.35*10**2
69 m_mars = 6.39*10**3
70 m_jupiter = 1.90*10**7
71 m_saturn = 5.68*10**6
72 m_uranus = 8.68*10**5
73 m_neptune = 1.02*10**6
74 m_pluto = 1.31*10**2
75 
76 #Stosunek predkosci innych planet do Ziemi
77 mercury_Realratio = 1.600
78 venus_Realratio = 1.177
79 earth_Realratio = 1.
80 mars_Realratio = 0.805
81 jupiter_Realratio = 0.437
82 saturn_Realratio = 0.324
83 uranus_Realratio = 0.228
84 neptune_Realratio = 0.182
85 pluto_Realratio = 0.158
86 
87 t = 0
88 dt = 0.01
89 #time_interval = 0.05
90 #time_interval_int = int(time_interval/dt)
91 
92 
93 graphpos = gdisplay (x=0, y=600, xtitle="Czas", ytitle="Pozycja", width=600, height=400,title= "Zmiana pozycji Ziemi i Ksiezyca w czasie" )
94 earthposx = gcurve(gdisplay=graphpos, color = color.green)
95 moonposx = gcurve(gdisplay=graphpos, color = color.white)
96 graphpos = gdisplay (x=0, y=0, xtitle="Czas", ytitle="Odleglosc", width=600, height=400,title= "Zmiana odleglosci Ksiezyca od Ziemi w czasie" )
97 distanceMoon_earthpos = gcurve(gdisplay=graphpos, color = color.green)
98 
99 
100 graphv = gdisplay (x=600, y=0, xtitle="Czas", ytitle="Predkosc", width=600, height=400, foreground = color.black, background = color.white, title = "Zmiana predkosci Ziemi w czasie")
101 earthvelocity = gcurve(gdisplay=graphv, color=color.blue)
102 
103 tlist = []
104 vlist = []
105 
106 graphGPE = gdisplay (x=600, y=400, xtitle="Pozycja", ytitle="Energia potencjalna grawitacji", width=800, height=400, title = "EPG i pozycja Ziemi wzgledem Slonca")
107 earthGPE = gcurve(gdisplay=graphGPE, color=color.green)
108 
109 
110 graphSpeedRatios = gdisplay (x=0, y=400, xtitle="Czas", ytitle="Stosunek predkosci", width=600, height=400, title = "Predkosci planet w stosunku do Ziemi")
111 mercuryRatio = gcurve (gdisplay=graphSpeedRatios, color=color.red)
112 mercuryRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.red)
113 
114 venusRatio = gcurve (gdisplay=graphSpeedRatios, color=color.orange)
115 venusRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.orange)
116 
117 earthRatio = gcurve (gdisplay=graphSpeedRatios, color=color.yellow)
118 earthRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.yellow)
119 
120 marsRatio = gcurve (gdisplay=graphSpeedRatios, color=color.green)
121 marsRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.green)
122 
123 jupiterRatio = gcurve (gdisplay=graphSpeedRatios, color=color.cyan)
124 jupiterRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.cyan)
125 
126 saturnRatio = gcurve (gdisplay=graphSpeedRatios, color=color.blue)
127 saturnRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.blue)
128 
129 uranusRatio = gcurve (gdisplay=graphSpeedRatios, color=color.magenta)
130 uranusRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.magenta)
131 
132 neptuneRatio = gcurve (gdisplay=graphSpeedRatios, color=color.red)
133 neptuneRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.red)
134 
135 plutoRatio = gcurve (gdisplay=graphSpeedRatios, color=color.orange)
136 plutoRealRatio = gdots (gdisplay=graphSpeedRatios, size=2, color=color.orange)
137 
138 
139 while True:
140  rate (10000) # 10000
141 
142  mercury.trail.append(pos=mercury.pos)
143  distanceMercury = mag(mercury.pos)
144  UnitVectorMercury = (mercury.pos - sun.pos)/distanceMercury
145  FgravMercury = (G*m_sun*m_mercury*UnitVectorMercury)/distanceMercury**2
146  mercury.velocity = mercury.velocity + (FgravMercury/m_mercury)*dt
147  mercury.pos = mercury.pos + mercury.velocity*dt
148  mercury.rotate(angle=radians(0.094), axis=(0,1,0))
149  if distanceMercury <= sun.radius: break
150  mercury_Ratio = mag(mercury.velocity) / mag(earth.velocity)
151 
152  venus.trail.append(pos=venus.pos)
153  distanceVenus = mag(venus.pos)
154  UnitVectorVenus = (venus.pos - sun.pos)/distanceVenus
155  FgravVenus = (G*m_sun*m_venus*UnitVectorVenus)/distanceVenus**2
156  venus.velocity = venus.velocity + (FgravVenus/m_venus)*dt
157  venus.pos = venus.pos + venus.velocity*dt
158  venus.rotate(angle=radians(0.023), axis=(0,1,0))
159  if distanceVenus <= sun.radius: break
160  venus_Ratio = mag(venus.velocity) / mag(earth.velocity)
161 
162  earth.trail.append(pos=earth.pos)
163  distanceEarth = mag(earth.pos)
164  UnitVectorEarth = (earth.pos - sun.pos)/distanceEarth
165  FgravEarth = (G*m_sun*m_earth*UnitVectorEarth)/distanceEarth**2
166  earth.velocity = earth.velocity + (FgravEarth/m_earth)*dt
167  earth.pos = earth.pos + earth.velocity*dt
168  earth.rotate(angle=radians(5.52), axis=(0,1,0))
169  earth_GPE = (G*m_sun*m_earth)/distanceEarth
170  if distanceEarth <= sun.radius: break
171  earth_Ratio = mag(earth.velocity) / mag(earth.velocity)
172 
173  moon.trail.append(pos=moon.pos)
174  distanceMoon_earth = mag(moon.pos - earth.pos)
175  distanceMoon_sun = mag(moon.pos - sun.pos)
176  UnitVectorMoon_earth = (moon.pos - earth.pos)/distanceMoon_earth
177  UnitVectorMoon_sun = (moon.pos - sun.pos)/distanceMoon_sun
178  FgravMoon_earth = (G*m_earth*m_moon*UnitVectorMoon_earth)/distanceMoon_earth**2
179  FgravMoon_sun = (G*m_sun*m_moon*UnitVectorMoon_sun)/distanceMoon_sun**2
180  moon.velocitylocal = moon.velocitylocal + (FgravMoon_earth/m_moon)*dt
181  moon.velocityglobal = moon.velocityglobal + (FgravMoon_sun/m_moon)*dt #earth.velocity
182  moon.pos = moon.pos + (moon.velocitylocal + earth.velocity)*dt
183  moon.rotate(angle=radians(5.52), axis=(0,1,0))
184 
185  mars.trail.append(pos=mars.pos)
186  distanceMars = mag(mars.pos)
187  UnitVectorMars = (mars.pos - sun.pos)/distanceMars
188  FgravMars = (G*m_sun*m_mars*UnitVectorMars)/distanceMars**2
189  mars.velocity = mars.velocity + (FgravMars/m_mars)*dt
190  mars.pos = mars.pos + mars.velocity*dt
191  mars.rotate(angle=radians(5.38), axis=(0,1,0))
192  if distanceMars <= sun.radius: break
193  mars_Ratio = mag(mars.velocity) / mag(mars.velocity)
194 
195  jupiter.trail.append(pos=jupiter.pos)
196  distanceJupiter = mag(jupiter.pos)
197  UnitVectorJupiter = (jupiter.pos - sun.pos)/distanceJupiter
198  FgravJupiter = (G*m_sun*m_jupiter*UnitVectorJupiter)/distanceJupiter**2
199  jupiter.velocity = jupiter.velocity + (FgravJupiter/m_jupiter)*dt
200  jupiter.pos = jupiter.pos + jupiter.velocity*dt
201  jupiter.rotate(angle=radians(13.46), axis=(0,1,0))
202  if distanceJupiter <= sun.radius: break
203  jupiter_Ratio = mag(jupiter.velocity) / mag(jupiter.velocity)
204 
205  saturn.trail.append(pos=saturn.pos)
206  distanceSaturn = mag(saturn.pos)
207  UnitVectorSaturn = (saturn.pos - sun.pos)/distanceSaturn
208  FgravSaturn = (G*m_sun*m_saturn*UnitVectorSaturn)/distanceSaturn**2
209  saturn.velocity = saturn.velocity + (FgravSaturn/m_saturn)*dt
210  saturn.pos = saturn.pos + saturn.velocity*dt
211  saturn.rotate(angle=radians(12.38), axis=(0,1,0))
212  if distanceSaturn <= sun.radius: break
213  saturn_Ratio = mag(saturn.velocity) / mag(saturn.velocity)
214 
215  uranus.trail.append(pos=uranus.pos)
216  distanceUranus = mag(uranus.pos)
217  UnitVectorUranus = (uranus.pos - sun.pos)/distanceUranus
218  FgravUranus = (G*m_sun*m_uranus*UnitVectorUranus)/distanceUranus**2
219  uranus.velocity = uranus.velocity + (FgravUranus/m_uranus)*dt
220  uranus.pos = uranus.pos + uranus.velocity*dt
221  uranus.rotate(angle=radians(7.36), axis=(0,1,0))
222  if distanceUranus <= sun.radius: break
223  uranus_Ratio = mag(uranus.velocity) / mag(uranus.velocity)
224 
225  neptune.trail.append(pos=neptune.pos)
226  distanceNeptune = mag(neptune.pos)
227  UnitVectorNeptune = (neptune.pos - sun.pos)/distanceNeptune
228  FgravNeptune = (G*m_sun*m_neptune*UnitVectorNeptune)/distanceNeptune**2
229  neptune.velocity = neptune.velocity + (FgravNeptune/m_neptune)*dt
230  neptune.pos = neptune.pos + neptune.velocity*dt
231  neptune.rotate(angle=radians(8.24), axis=(0,1,0))
232  if distanceNeptune <= sun.radius: break
233  neptune_Ratio = mag(neptune.velocity) / mag(neptune.velocity)
234 
235  pluto.trail.append(pos=pluto.pos)
236  distancePluto = mag(pluto.pos)
237  UnitVectorPluto = (pluto.pos - sun.pos)/distancePluto
238  FgravPluto = (G*m_sun*m_pluto*UnitVectorPluto)/distancePluto**2
239  pluto.velocity = pluto.velocity + (FgravPluto/m_pluto)*dt
240  pluto.pos = pluto.pos + pluto.velocity*dt
241  pluto.rotate(angle=radians(0.86), axis=(0,1,0))
242  if distancePluto <= sun.radius: break
243  pluto_Ratio = mag(pluto.velocity) / mag(pluto.velocity)
244 
245  earthposx.plot(pos=(t,earth.pos.x))
246  earthvelocity.plot(pos=(t,(earth.velocity.x**2 + earth.velocity.z**2)**1/2))
247  earthGPE.plot(pos=(earth.pos.x,earth_GPE))
248  moonposx.plot(pos=(t,moon.pos.x))
249  distanceMoon_earthpos.plot(pos=(t,distanceMoon_earth))
250 
251  vlist.append(earth.velocity.x)
252  tlist.append(t)
253  t = t + dt
254 
255  mercuryRatio.plot(pos=(t,mercury_Ratio))
256  mercuryRealRatio.plot(pos=(t,mercury_Realratio))
257 
258  venusRatio.plot(pos=(t,venus_Ratio))
259  venusRealRatio.plot(pos=(t,venus_Realratio))
260 
261  earthRatio.plot(pos=(t,earth_Ratio))
262  earthRealRatio.plot(pos=(t,earth_Realratio))
263 
264  marsRatio.plot(pos=(t,mars_Ratio))
265  marsRealRatio.plot(pos=(t,mars_Realratio))
266 
267  jupiterRatio.plot(pos=(t,jupiter_Ratio))
268  jupiterRealRatio.plot(pos=(t,jupiter_Realratio))
269 
270  saturnRatio.plot(pos=(t,saturn_Ratio))
271  saturnRealRatio.plot(pos=(t,saturn_Realratio))
272 
273  uranusRatio.plot(pos=(t,uranus_Ratio))
274  uranusRealRatio.plot(pos=(t,uranus_Realratio))
275 
276  neptuneRatio.plot(pos=(t,neptune_Ratio))
277  neptuneRealRatio.plot(pos=(t,neptune_Realratio))
278 
279  plutoRatio.plot(pos=(t,pluto_Ratio))
280  plutoRealRatio.plot(pos=(t,pluto_Realratio))
281 
282 
283 
284 
285