0

私は開発中の小さな物理玩具アプリケーションを持っています。パーティクルが互いに押しのけず、引き寄せるだけであることを除いて、正常に動作します。コマンドごとにサブを通過するサブをデバッグし、値「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
4

1 に答える 1

2

精神的なデバッグは、あなたが持っていることを教えてくれますOption Strict Off. VB.NET を使用する場合はOption Strict On、実際にの遅延バインディング機能が必要Offでない限り、常に を使用することをお勧めします。あなたが持っている場合Option Strict On、あなたは得るでしょう

エラー BC30512: Option Strict On は、'Double' から 'Integer' への暗黙的な変換を許可しません

Math.Sqrttoの結果の割り当てについてh。@Marc Gravell が暗示しているように、ここでは丸めの問題が発生する大きな可能性hがありIntegerます。

于 2011-02-03T09:44:01.097 に答える