我在编一个求点集凸包的程序
采点集的程序部分已经搞定了但到了去极点部分就老提示下标越界
下面是我的程序:
Option Explicit Private Type pointinfo x As Single '点的x 坐标值 y As Single '点的y 坐标值 q As Single '与水平线的夹角 End Type Dim p0 As pointinfo Dim p(1 To 200) As pointinfo '点集 Dim ps(1 To 200) As pointinfo '排序后的点集 Dim pi(1 To 200) As pointinfo '极点 Dim n, m, d As Integer Dim x0, y0 As Single Dim l, e As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) DrawWidth = 4 If n = 0 Then p0.x = x p0.y = y Circle (x, y), 100, RGB(255, 0, 255) Else '输入点集 p(n).x = x p(n).y = y Circle (x, y), 10, RGB(255, 255, 0) End If n = n + 1 x0 = x y0 = y
End Sub
Private Sub Command2_Click() Dim i As Integer Dim q As Single p(n).x = x0 p(n).y = y0 Const pi = 3.14 For i = l To n If p(i).y - p0.y = 0 Then (总是在这句提示下标越界) If p(i).x - p0.x = 0 Then p(i).q = 90 ElseIf p(i).x - p0.x > 0 Then p(i).q = 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x)) Else p(i).q = 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x)) + 180 End If ElseIf p(i).y - p0.y < 0 Then If p(i).x - p0.x = 0 Then p(i).q = 270 ElseIf p(i).x - p0.x > 0 Then p(i).q = 360 + 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x)) Else p(i).q = 180 + 180 / pi * Atn((p(i).y - p0.y) / (p(i).x - p0.x)) End If End If Next i
End Sub |