Dim int点(1 To 10, 1 To 2) As Integer
Dim int当前位置 As Integer
Dim inttemp As Integer
Dim int中心位置X As Integer
Dim int中心位置Y As Integer
Dim int角度(1 To 10, 1 To 2) As Double
Private Sub 确定中心位置()
Dim lngtemp As Long
Dim lngtmp As Long
Dim inttmp As Integer
lngtmp = 0
lngtemp = 0
inttmp = 0
For inttemp = 1 To 10
lngtmp = lngtmp + int点(inttemp, 1)
lngtemp = lngtemp + int点(inttemp, 2)
inttmp = inttmp + 1
Next
int中心位置X = lngtmp / inttmp
int中心位置Y = lngtemp / inttmp
End Sub
Private Sub 画多边形()
Dim inttmp As Integer
Dim int临时 As Integer
Dim douswap As Double
For inttemp = 1 To 10
int角度(inttemp, 1) = inttemp
'判断在哪个象限
If int点(inttemp, 1) > int中心位置X And int点(inttemp, 2) < int中心位置Y Then
int角度(inttemp, 2) = Atn((int中心位置Y - int点(inttemp, 2)) / (int点(inttemp, 1) - int中心位置X))
End If
If int点(inttemp, 1) < int中心位置X And int点(inttemp, 2) < int中心位置Y Then
int角度(inttemp, 2) = (1.5707963 - Atn((int中心位置Y - int点(inttemp, 2)) / (int中心位置X - int点(inttemp, 1)))) + 1.5707963
End If
If int点(inttemp, 1) < int中心位置X And int点(inttemp, 2) > int中心位置Y Then
int角度(inttemp, 2) = Atn((int点(inttemp, 2) - int中心位置Y) / (int中心位置X - int点(inttemp, 1))) + 3.1415926
End If
If int点(inttemp, 1) > int中心位置X And int点(inttemp, 2) > int中心位置Y Then
int角度(inttemp, 2) = (1.5707963 - Atn((int点(inttemp, 2) - int中心位置Y) / (int点(inttemp, 1) - int中心位置X))) + 4.7123889
End If
Next
'排序
For inttemp = 1 To 9
For inttmp = inttemp + 1 To 10
If int角度(inttemp, 2) > int角度(inttmp, 2) Then
'交换
douswap = int角度(inttemp, 2)
int角度(inttemp, 2) = int角度(inttmp, 2)
int角度(inttmp, 2) = douswap
douswap = int角度(inttemp, 1)
int角度(inttemp, 1) = int角度(inttmp, 1)
int角度(inttmp, 1) = douswap
End If
Next
Next
If 判断是否存在平角 = False Then
'画画
For inttemp = 1 To 9
inttmp = int角度(inttemp, 1)
int临时 = int角度(inttemp + 1, 1)
Picture1.Line (int点(inttmp, 1), int点(inttmp, 2))-(int点(int临时, 1), int点(int临时, 2))
Next
inttmp = int角度(10, 1)
int临时 = int角度(1, 1)
Picture1.Line (int点(inttmp, 1), int点(inttmp, 2))-(int点(int临时, 1), int点(int临时, 2))
Else
MsgBox "存在平角"
End If
End Sub
Private Sub Command2_Click()
Form_Load
End Sub
Private Sub Command1_Click()
确定中心位置
画多边形
End Sub
Private Function 判断是否存在平角() As Boolean
Dim blntmp As Boolean
Dim doutemp As Double
Dim doutmp As Double
Dim int1 As Integer
Dim int2 As Integer
Dim int3 As Integer
blntmp = False
Private Sub Form_Load()
Command1.Caption = "画多边形"
Command1.Enabled = False
Command2.Caption = "初始化"
Text1.Text = "10"
Picture1.AutoRedraw = True
Picture1.Cls
int当前位置 = 1
For inttemp = 1 To 10
int点(inttemp, 1) = -1
int点(inttemp, 2) = -1
Next
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If int当前位置 = 11 Then Exit Sub
int点(int当前位置, 1) = X
int点(int当前位置, 2) = Y
Picture1.Circle (X, Y), 10
Picture1.Print int当前位置
int当前位置 = int当前位置 + 1
Me.Caption = int当前位置 - 1
If int当前位置 = 11 Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End If