Водолаз прыгает вертикально вниз в воду.График графика в реальном масштабе времени за другим
Я хочу построить движение дайвера перед погружением в воду (от t = 0 до t = Tc, Tc в момент, когда он касается воды), причем его положение обе оси зависят от времени, следуя его движению после погружения в воду (t> Tc)
Мне удалось построить график реального времени, изображающий его движение, прежде чем погрузиться в воду, но как добавить/заменить другим уравнением после того, как он войдет в воду?
Кстати, как проследить уровень воды, который является фиксированной горизонтальной линией при y = 0?
Вот мой код:
# -*- coding: utf-8 -*-
from math import *
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
print ("Height of diver (m) and weight of diver (kg)")
h = float(input(" height = "))
m = float(input(" mass = "))
g = 9.81 #gravity = 10 m/s^2
Tc = sqrt(2*h/g) #Tc = the time the diver touches water
Tc = round(Tc,2)
Ve = g*Tc #Ve = His initial velocity before plunging into water
Ve = round (Ve,2)
## movement in the water
#calculation of velocity's limit
dh = 0.9 #bouyancy, dh=0.9
k = 250 #coefficient of friction , k =250 kg/s
rate = m/k
Vlim = rate*g*(1-(1/dh))
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-30, h+1)) #ymax : initial height+1
line, = ax.plot([], [], ' o', lw=2)
step = 0.1 # animation step
xs = [1] # the vertical position is fixed on x-axis
ys = [h]
# animation function. This is called sequentially
def animate(y):
ys[-1] = y
line.set_data(xs, ys)
return line,
def get_y():
t = 0
while t <= Tc:
y = -0.5 * g * t**2 + h # the equation of diver's displacement on y axis
yield y
t += step
while t > Tc:
y = rate*Ve*(exp(-Tc/rate)-exp(-t/rate)) + rate*(abs(Vlim))*(exp(-Tc/rate)-exp(-t/rate)) + (abs(Vlim))*(Tc-t) # equation of diver's displacement in water on y axis
yield y
t += step # Indentation Error fixed
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, frames=get_y, interval=100)
plt.show()
код имеет 'IndentationError' на' t + = step' –
'taux' не определен –
Извините, я заменил его на курс. –