私は開発中の小さな物理玩具アプリケーションを持っています。パーティクルが互いに押しのけず、引き寄せるだけであることを除いて、正常に動作します。コマンドごとにサブを通過するサブをデバッグし、値「H」が変更されないことに気付きました。この値を変更するには、手動で「h = 1」に設定するしかありません。「H」値で計算をやり直すと、x1、y1、x2、y2 がすべて異なっていても、以前の値にリセットされます。つまり、H は異なるはずです。
どこかで数学的な間違いを犯したのは私だと思いますが、どこにあるのかわかりません。自分の作品を見渡す新鮮な目が必要です。何か見つけたら教えてください。
ありがとう。
Public Sub movenodes()
For i As Integer = 0 To connectionnumber
If connections(i).exists = True Then
Dim n1x As Integer
Dim n2x As Integer
Dim n1y As Integer
Dim n2y As Integer
Dim h As Integer
n1x = nodes(connections(i).node1).x
n2x = nodes(connections(i).node2).x
n1y = nodes(connections(i).node1).y
n2y = nodes(connections(i).node2).y
h = 1
h = Math.Sqrt(((nodes(connections(i).node1).x + nodes(connections(i).node2).x) ^ 2) + ((nodes(connections(i).node1).y + nodes(connections(i).node2).y) ^ 2))
Me.Text = nodes(connections(i).node1).x & " " & nodes(connections(i).node1).y & " " & h
If h > connections(i).happy Then
If n1x > n2x Then
nodes(connections(i).node1).hspeed -= 0.1
nodes(connections(i).node2).hspeed += 0.1
ElseIf n1x < n2x Then
nodes(connections(i).node1).hspeed += 0.1
nodes(connections(i).node2).hspeed -= 0.1
End If
If n1y > n2y Then
nodes(connections(i).node1).vspeed -= 0.1
nodes(connections(i).node2).vspeed += 0.1
ElseIf n1y < n2y Then
nodes(connections(i).node1).vspeed += 0.1
nodes(connections(i).node2).vspeed -= 0.1
End If
ElseIf h < connections(i).happy Then
MsgBox("")
If n1x > n2x Then
nodes(connections(i).node1).hspeed += 0.5
nodes(connections(i).node2).hspeed -= 0.5
ElseIf n1x < n2x Then
nodes(connections(i).node1).hspeed -= 0.5
nodes(connections(i).node2).hspeed += 0.5
End If
If n1y > n2y Then
nodes(connections(i).node1).vspeed += 0.5
nodes(connections(i).node2).vspeed -= 0.5
ElseIf n1y < n2y Then
nodes(connections(i).node1).vspeed -= 0.5
nodes(connections(i).node2).vspeed += 0.5
End If
End If
End If
Next
End Sub