#Working on Projectile Motion Animation: Stuck at animation and Graph T_T

14 messages · Page 1 of 1 (latest)

wind swallow
#

import matplotlib
from math import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation, rc
from IPython.display import HTML
from matplotlib.animation import FuncAnimation


#@title Initial Speed Calculator



Initial_Height = 10 #@param{type: "raw" }
Distance = 750 #@param{type: "raw" }
Angle = 35 #@param{type: "raw" }

D = radians(Angle)
 

a = round(4.9 * (Distance ** 2),2)
b = (Initial_Height + round(tan(D),2)*Distance) * round((cos(D))**2,2)
Vo = round(sqrt(a/b),3)

Vox = Vo * cos(D)
Voy = Vo * sin(D)


Max_H = round(((Vo*sin(D))**2)/(2*9.81),2)

print(Vo)
print(Max_H)
Time = round(Distance/Vox,3)

print(Time)

fig, ax1 = plt.subplots()
q = np.linspace(0, Time + 2)
Y = Initial_Height + (Voy * q) + (.5 * -9.81 * (q**2)) 
X = Vox * q

plt.xlim(0, Distance + 20)
plt.ylim(0, Max_H + 20)
plt.plot(X, Y, "--")

plt.show()

fig, ax2 = plt.subplots()
w = np.linspace(0, Time + 2)
Y = Initial_Height + (Voy * q) + (.5 * -9.81 * (q**2)) 
X = Vox * q
line, = ax2.plot(X, Y)

plt.xlim(0, Distance + 20)
plt.ylim(0, Max_H + 20)

def animate(i):
  line.set_ydata(Initial_Height + (Voy * (q+i)) + (.5 * -9.81 * (q+i)**2))
  line.set_xdata(Vox * (q+i))
  return line,

ani  = animation.FuncAnimation(fig, 
  animate, interval=100, blit=True, save_count=50)

rc('animation', html='jshtml')
ani

blazing sphinx
#

!format py

tranquil ingotBOT
#
Code Formatting

When sharing code with the community, please use the correct formatting for ease of readability.

Example

```py
YOUR CODE HERE
```

Those are back ticks not single quotes, typically the key above TAB

wind swallow
#

Thanks I was wondering how to properly make a post my bad

#

Done

#

Thanks a lot

blazing sphinx
#

You haven't explained what the problem is

wind swallow
#

1st problem: The animation starts with a fully formed line path then would slowly disappear (The opposite was whats supposed to happen having an empty frame at the beginning then having a path slowly form during animation)

#

2nd problem: How to put a moving "projectile" in the program

#

3rd problem: How to put solid "platform" to project the Initial_Height(I tried to use " matplotlib.patches.Rectangle((0,0),2,Initial_Height) " and it didn't work sadly)

wind swallow
#

4th problem: How to sync "Time" with everything in the program such that the animation will stop approximately around the time that the projectile launched reaches the ground

blazing sphinx
#

That's a pretty cool use of matplotlib's animation library

#

But I'm not quite sure how to help you sorry

#

Maybe someone else will