2016-04-05 6 views
0

ダイバーが垂直に水中にジャンプします。別のリアルタイムグラフにプロットする

私は水中に潜る前にダイバーの動きをプロットしたいと思います(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() 
+0

コードに 't + = step'に' IndentationError'があります –

+0

'taux'が定義されていません –

+0

申し訳ありませんが、私はそれをレートで置き換えました。 –

答えて

1

今のコードが動作している:

は、ここに私のコードです。私は

y = -(t - Tc) 

代わりに

y = rate*Ve*(exp(-Tc/rate)-exp(-t/rate)) + rate*(abs(Vlim))*(exp(-Tc/rate)-exp(-t/rate)) + (abs(Vlim))*(Tc-t) 

を代入試験し、粒子が一定の速度で移動します。 ダイバーが水の導入を中止したことが間違っているようです。

+0

あなたは正しいです!ちなみに、y = 0の背景に固定された水平線を追加する方法は? –

+0

これは話題にはなりませんが、とにかくコードに 'plt.axhline(0)'を追加する必要があります。あなたの問題を解決した場合は、答えを確認してください。 –

関連する問題