xinghesnak发表于2006-5-15 9:43:00
如果是排序,我这样写的:
Private Sub Command2_Click()Dim i As Integer, j As IntegerDim term As pointinfoFor i = 1 To n ...
呵呵,这个方法很奏效.谢谢.
为了从p(0)开始计点,我把form-click()部分给改写了下。
但是我在往下编写求其他各点与排序后的极植点p(0)所在水平线的角度p(i).q时,又出现了值传递问题。p(i).q的值总是0,而不是程序的计算值。下面是我的程序:
Option Explicit Private Type pointinfo x As Single '点的x 坐标值 y As Single '点的y 坐标值 q As Single '与水平线的夹角 End Type Dim p0 As pointinfo Dim p(0 To 200) As pointinfo '点集 Dim pl(0 To 200) As pointinfo '求出起始点 Dim ps(0 To 200) As pointinfo '排序后的点集 Dim pi(0 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 p(0).x = x p(0).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 '我后改写的部分
End Sub
Private Sub Command2_Click() Dim i As Integer Dim q As Single Const pi = 3.14
Dim u As Integer, j As Integer '将p()排序y有小至大。 Dim term As pointinfo For u = 1 To n - 1 For j = 1 To n - u If p(j).y < p(j - 1).y Or (p(j).y = p(j - 1).y And p(j).x < p(j - 1).x) Then term.x = p(j - 1).x: term.y = p(j - 1).y p(j - 1).x = p(j).x: p(j - 1).y = p(j).y p(j).x = term.x: p(j).y = term.y End If Next j Next u
For i = 1 To n - 1 '我计算角度的程序 If p(i).y - p(0).y = 0 Then If p(i).x - p(0).x = 0 Then p(i).q = 90 ElseIf p(i).x - p(0).x > 0 Then p(i).q = 180 / pi * Atn((p(i).y - p(0).y) / (p(i).x - p(0).x)) Else p(i).q = 180 / pi * Atn((p(i).y - p(0).y) / (p(i).x - p(0).x)) + 180 End If ElseIf p(i).y - p(0).y < 0 Then If p(i).x - p(0).x = 0 Then p(i).q = 270 ElseIf p(i).x - p(0).x > 0 Then p(i).q = 360 + 180 / pi * Atn((p(i).y - p(0).y) / (p(i).x - p(0).x)) Else p(i).q = 180 + 180 / pi * Atn((p(i).y - p(0).y) / (p(i).x - p(0).x)) End If End If Next i
End Sub
|