• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 23rd, 2020 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. '''
2. Luke Marshall
3. Abir Quabili
4. University of Delaware
5. MEEG211 - Dynamics
6. Project 1
7. Problem 2 - Rectangle
8. '''
9.
10. import math
11. import matplotlib.pyplot as plt
12.
13. # FUNCTIONS ##################################################################
14.
15. # def trajCalc(vox, vy, g, t, xa, h):
16.
17. #     vy = vy - g*t
18.
19. #     xa = xa + vox*t
20.
21. #     h = h + vy*t - (1/2)*(g)*(t**2)
22.
23. #     t = t + 0.1
24.
25. #     # print(vy, h, xa);
26.
27. #     return [xa, h]
28.
29. # def alphaCalc(vo, g, xa, ht):
30.
31. #     a = -(g*(xa**2))/(2*(vo**2))
32. #     b = (xa)
33. #     c = -(g*(xa**2))/(2*(vo**2)) - ht
34.
35. #     tanAlpha = (-b - (b**2 - 4*a*c)**(1/2))/(2*a)
36. #     alpha = (-math.atan(tanAlpha))
37.
38. #     vox = vo*(math.cos(alpha));
39. #     vy = vo*(math.sin(alpha));
40.
41. #     return [alpha, vox, vy]
42.
43. ##############################################################################
44.
45. g = 9.8
46. h = 0.0
47. xa = -50.0
48. t = 0
49. d = -10
50.
51. xao = xa
52.
53. n1 = 0
54.
55. x = []
56. y = []
57. xvoList = []
58.
59. nx = len(x) - 1;
60. ny = len(y) - 1;
61.
62. vo = 32
63. ht = 33
64.
65. z = 0
66.
67. j = 1
68.
69. a = -(g*(xa**2))/(2*(vo**2))
70. b = (xa)
71. c = -(g*(xa**2))/(2*(vo**2)) - ht
72.
73. tanAlpha = (-b - (b**2 - 4*a*c)**(1/2))/(2*a)
74. alpha = (-math.atan(tanAlpha))
75.
76. vox = vo*(math.cos(alpha));
77. vy = vo*(math.sin(alpha));
78.
79. while (z != 1):
80.
81.     print('loop: ' + str(j))
82.
83.     j = j + 1
84.
85.     while ((xao <= 0) and (h != ht)):
86.
87.         #print(vy, h, xa);
88.
89.         vy = vy - g*t
90.
91.         xao = xao + vox*t
92.
93.         h = h + vy*t - (1/2)*(g)*(t**2)
94.
95.         t = t + 0.01
96.
97.         x.append(xa)
98.         y.append(h)
99.
100.     xa = xa - 0.1
101.
102.     n = len(x) - 1
103.
104.     m = 0
105.
106.     while m != n:
107.
108.         if x[m] < -10:
109.
110.             m = m + 1
111.
112.         elif y[m] > 33:
113.
114.             print('Yay')
115.
116.             break
117.
118.         elif y[m] <= 33:
119.
120.             print('Hit')
121.
122.             vo = vo - 0.1
123.
124.             break
125.
126.         else:
127.
128.             print('No')
129.
130.             break
131.
132.     for i in y:
133.
134.         if i > 35:
135.
136.             vo = vo - 0.1
137.
138.             break
139.
140.     # while ((x[m] >= -10) and (y[m] >= 33)):
141.
142.     # print(x)
143.
144.     # print(y)
145.
146.     # while m != n:
147.
148.     #     if (x[m] < -10):
149.
150.     #         print('If')
151.
152.     #         m = m + 1
153.
154.     #     elif (y[m] <= 33):
155.
156.     #         print('Elif 1')
157.
158.     #         # vo = vo - 0.1
159.
160.     #         xa = xa + 0.1
161.
162.     #         break
163.
164.     #     elif (y[m] > 35):
165.
166.     #         print('Elif 2')
167.
168.     #         # xa = xa + 0.1
169.
170.     #         vo = vo + 0.1
171.
172.     #         break
173.
174.     #     else:
175.
176.     #         print('Else')
177.
178.     #         z = 1
179.
180.     #         break
181.
182.     xvoList.append([vo, xa])
183.
184.     a = -(g*(xa**2))/(2*(vo**2))
185.     b = (xa)
186.     c = -(g*(xa**2))/(2*(vo**2)) - ht
187.
188.     # while ((b**2) >= (4*a*c)):
189.
190.     #     vo = vo + 0.1
191.
192.     #     a = -(g*(xa**2))/(2*(vo**2))
193.
194.     #     b = (xa)
195.
196.     #     c = -(g*(xa**2))/(2*(vo**2)) - ht
197.
198.     tanAlpha = (-b - (b**2 - 4*a*c)**(1/2))/(2*a)
199.     alpha = (-math.atan(tanAlpha))
200.
201.     vox = vo*(math.cos(alpha));
202.     vy = vo*(math.sin(alpha));
203.
204.     # alphaList = alphaCalc(vo, g, xa, ht)
205.
206.     # alpha = alphaList[0]
207.     # vox = alphaList[1]
208.     # vy = alphaList[2]
209.
210. print(xvoList)
211.
212. xvoListSuccessN = len(x) - 2;        # [vo and xa]
213.
214. xvoListSuccess = xvoList[xvoListSuccessN]
215.
216. voxOptimal = xvoListSuccess[0]
217.
218. xaOptimal = xvoListSuccess[1]
219.
220. print('Optimal Initial Velocity: ' + str(voxOptimal))
221. print('Optimal X Distance: ' + str(xaOptimal))
222.
223. plt.plot(x,y)
224. plt.xlabel('X')
225. plt.ylabel('h')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top