[.NET] 鍵盤移動和runge kutta衝突

看板Visual_Basic作者 (earric9972202)時間6年前 (2018/04/02 21:53), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請輸入專案類型(網站專案或者應用程式專案): 應用程式專案 我正在打一個使用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://www.ptt.cc/bbs/Visual_Basic/M.1522677189.A.952.html
文章代碼(AID): #1QmZN5bI (Visual_Basic)
文章代碼(AID): #1QmZN5bI (Visual_Basic)