私はVB6でJavaで行われたこのギフトラッピングアルゴリズム(yoshihitoyagi!)を実装しようとしています。これを適切に行ったと確信していますが、何らかの理由で機能しません。返された配列には 1 つの要素しかありません。誰かが(新しい目で)見て、あからさまに何かを見逃しているかどうかを知らせてくれることを望んでいました.
これが私のコードです:
Function small(ByVal Current As Integer, ByVal smallest As Integer, ByVal i As Integer) As Boolean
Dim xa, ya, xb, yb, val As Integer
xa = xPoints(smallest) - xPoints(Current)
xb = xPoints(i) - xPoints(Current)
ya = yPoints(smallest) - yPoints(Current)
yb = yPoints(i) - yPoints(Current)
val = xa * yb - xb * ya
If val > 0 Then
small = True
ElseIf val < 0 Then
small = False
Else
If (xa * xb + ya * yb) < 0 Then
small = False
Else
If (xa * xa + ya * ya) > (xb * xb + yb * yb) Then
small = True
Else
small = False
End If
End If
End If
End Function
Sub CreateContours1()
Dim Min, i, num, smallest, Current, contourcount2 As Integer
Dim xPoints2(), yPoints2() As Long
'Find leftmost lowest point
Min = 1
For i = 1 To contourCount
If yPoints(i) = yPoints(Min) Then
If xPoints(i) < xPoints(Min) Then
Min = i
End If
ElseIf yPoints(i) < yPoints(Min) Then
Min = i
End If
Next
Debug.Print "Min: " & Min
Current = Min
num = 1
Do
contourcount2 = contourcount2 + 1
ReDim Preserve xPoints2(contourcount2)
ReDim Preserve yPoints2(contourcount2)
xPoints2(num) = xPoints(Current)
yPoints2(num) = yPoints(Current)
Debug.Print "num: " & num & ", current: " & Current & "(" & xPoints(Current) & ", " & yPoints(Current) & ")"
num = num + 1
smallest = 1
If smallest = Current Then
smallest = 1
End If
For i = 1 To contourCount
If (Current = i) Or (smallest = i) Then
GoTo continue_loop
End If
If small(Current, smallest, i) Then
smallest = i
End If
Next
Current = smallest
continue_loop:
Loop While Current <> Min
End Sub
すべての配列は 1 から始まります。したがって、1 と 0 の間に違いがある場合は、それが理由です。
これがたくさんあることは理解していますが、どんな助けでも大歓迎です。
ありがとう!!!!