作者earric (earric9972202)
看板Visual_Basic
标题[.NET] 键盘移动和runge kutta冲突
时间Mon Apr 2 21:53:07 2018
请输入专案类型(网站专案或者应用程式专案):
应用程式专案
我正在打一个使用runge kutta 和键盘操控左右的方程式,图片示意:
http://i.imgur.com/W8Rrx2P.jpg
上方的饮料以runge kutta 移动
下方的狗狗以键盘左右移动
原本狗狗是可以移动的,但是加上runge kutta的程式後就不能动了,请问是哪里冲突了?
谢谢各位~~
程式:
Public Class Form1
Dim y1, x1, z1, w1, t, dt, a As Double
Dim k1, d1, k2, d2, k3, d3, k4, d4, y2, z2 As Double
Dim p1, q1, p2, q2, p3, q3, p4, q4, x2, w2 As Double
'狗狗的程式'
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case 37
PictureBoxdog.Left = PictureBoxdog.Left - 30
Case 39
PictureBoxdog.Left = PictureBoxdog.Left + 30
End Select
End Sub
'饮料的程式'
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
y1 = 90
z1 = 0
x1 = 90
w1 = 50
a = 1
dt = 0.001
Do While a <= 100000
k1 = dt * z1
p1 = dt * w1
d1 = dt * f(t, y1, z1)
q1 = dt * f(t, x1, w1)
k2 = dt * (z1 + d1 / 2)
p2 = dt * (w1 + q1 / 2)
d2 = dt * f(t + dt / 2, y1 + k1 / 2, z1 + d1 / 2)
q2 = dt * f(t + dt / 2, x1 + p1 / 2, w1 + q1 / 2)
k3 = dt * (z1 + d2 / 2)
p3 = dt * (w1 + q2 / 2)
d3 = dt * f(t + dt / 2, y1 + k2 / 2, z1 + d2 / 2)
q3 = dt * f(t + dt / 2, x1 + p2 / 2, w1 + q2 / 2)
k4 = dt * (z1 + d3)
p4 = dt * (w1 + q3)
d4 = dt * f(t + dt, y1 + k3, z1 + d3)
q4 = dt * f(t + dt, x1 + p3, w1 + q3)
y2 = y1 + (k1 + 2 * k2 + 2 * k3 + k4) / 6
x2 = x1 + (p1 + 2 * p2 + 2 * p3 + p4) / 6
z2 = z1 + (d1 + 2 * d2 + 2 * d3 + d4) / 6
w2 = w1 + (q1 + 2 * q2 + 2 * q3 + q4) / 6
t = t + dt
y1 = y2
x1 = x2
z1 = z2
w1 = w2
a += 1
food13.Location = New Point(x1, y1)
Application.DoEvents()
Loop
End Sub
Function f(ByVal t, ByVal y1, ByVal z1)
Dim g As Integer
g = 9.81
f = g
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.200.41.141
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Visual_Basic/M.1522677189.A.952.html