求助 小球坠地弹起衰减的过程
在实现循环上,我老写不对语句,急了就想编写个小球坠地弹起衰减的过程试验一下,还是想不出来怎么实现,用数组是因不会让球停止,我就让他弹个一百次,也能看一会了,可是球落下去就弹不起来了,只表现出小球一直自由坠落下去,我想让球落到高度3000再往上弹起,落下再弹起就不会了。Dim t As Single '时间
Dim y As Single '球心纵坐标
Dim k As Single '弹起后的恢复系数
Dim g As Single '重力加速度
Dim v(1 To 100) As Single '碰前速度
Dim vy(1 To 100) As Single '碰后速度
Dim ts As Single '一个弹起后到碰撞前的瞬时时间
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Cls
t = t + 0.05
g = 4000 '用9.8感觉不对,因为单位问题我还是没搞明白,看默认单位叫缇,挺小,就弄大点4000了
k = -0.8 '地面衰减值,负号因为窗口往下为正方向
y = 4000 * t ^ 2 / 2
Circle (1000, y), 200 '设加速度为每秒4000,圆半径为200
If y = 3000 Then
ty = t
v(1) = Sqr(24) * 1000
For i = 1 To 100
vy(i) = k * v(i)
ts = t - ty
y = -vy(i) * ts + ts ^ 2 *g / 2
Circle (1000, y), 200
If y = 3000 Then ty = ty + ts: v(i + 1) = vy(i) - g * ts
Next i
End If
End Sub