-
Notifications
You must be signed in to change notification settings - Fork 0
/
going_through_earth.py
49 lines (38 loc) · 1.51 KB
/
going_through_earth.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
import matplotlib.pyplot as plt
#Data
earth_radius = 6371000
m = 70 #mass of the particle
earth_mass = 5.972*10**24
position = earth_radius
t = 0
G = -6.674*10**-11 #Gravitational constant
v = 0 #Initial velocity
dt = 10
def defining_Gravity(position):
acceleration = (earth_mass*position*G)/(earth_radius**3)
#Acceleration of the particle as it passes through earth
return acceleration
def potential_energy_curve(position, gravity):
return -m*defining_Gravity(position)*position
def kinetic_energy_curve(velocity):
return 0.5*m*velocity**2
def time_of_arrival(t, position, v):
fig, ax = plt.subplots(3) #Three different graphs
while earth_radius + position >= 0:
gravity = defining_Gravity(position)
#Invoking the acceleration of the particle depending on the position
ax[0].plot(t, abs(position), ".b")
ax[0].set_title("Position in time")
#Plotting the particle´s position as it goes through earth
ax[1].plot(t, kinetic_energy_curve(v), ".r")
ax[1].set_title("Kinetic energy")
ax[2].plot(t, potential_energy_curve(position, gravity), ".g")
ax[2].set_title("Potential energy")
v = v + gravity*dt
position = position + v*dt
arrival_time = t/3600
t = t + dt
return arrival_time
time = time_of_arrival(t, position, v)
print("Time for reaching the opposite end of earth:", time, " hours")
plt.show()