-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation_python code.py
55 lines (44 loc) · 1.62 KB
/
simulation_python code.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
from turtle import color
from matplotlib import pyplot as plt
from matplotlib import animation
import math
g = 9.8
u = eval(input("Enter the initial velocity(>44.27): ")) # velocity in swinging phase
v = 2*u #velocity in supporting phase
theta = eval(input("Enter the initial angle: "))
time_swinging_phase = 2*u*math.sin(math.radians(theta))/g
total_time = (5*time_swinging_phase)/4
x = -100 # starting position
def time_list(): #for generating a list of times at dt interval
intervals = []
t = 0
dt = 0.01
while t <= total_time:
intervals.append(t)
t = t + dt
return intervals
def change_position(i, circle, intervals, u, theta):
t = intervals[i]
if t < time_swinging_phase :
x = -100 + (u*math.cos(math.radians(theta))*t)
y = (u*math.sin(math.radians(theta))*t - (0.5*g*t*t))
else : #supporting phase
y = 0
x = 100 - (v*(t-time_swinging_phase))
circle.center = x, y
return circle
intervals = time_list()
xmin = -100
xmax = 100
ymin = 0
ymax = (u*u)/(2*g)
fig = plt.gcf() # to get the current figure
axis = plt.axes(xlim=(xmin-150,xmax+150 ), ylim=(ymin-50,ymax+100))
circle = plt.Circle((xmin, ymin), 10, color='r')
axis.add_patch(circle)
anim = animation.FuncAnimation(fig, change_position,
fargs=(circle, intervals, u, theta),
frames=len(intervals), interval=20,
repeat=True)
plt.grid(True)
plt.show()