|
问题的提出:
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=13701
代码:
[code]
Option Explicit
Const CLEARCMD = vbCr & " " & vbCr
Dim Pi As Double
Public Sub LinePointArray()
Dim PointArray() As Double, PointIndex() As Integer, CurPIndex As Integer
Dim i As Integer, N As Integer
Dim TempPoint As Variant, Temp As Variant, TempIndex As Integer
Dim StartPoint(0 To 2) As Double
Dim TempAngle As Double
Dim ii As Integer
Dim BasePoint(0 To 2) As Double, SecendPoint(0 To 2) As Double
Dim P1(0 To 2) As Double, P2(0 To 2) As Double
Dim BaseAngle As Double, Direction As Integer
Pi = Atn(1) * 4
On Error Resume Next
'Open "D:\Test.txt" For Output As #1
Do
ReDim Preserve PointArray(0 To 2, N)
TempPoint = ThisDrawing.Utility.GetPoint(, CLEARCMD & "请选择点(" & N & "):")
If Err Then
Err.Clear
N = N - 1
If N = PointArray(0, i) Then
Temp = PointArray(0, i)
TempIndex = i
End If
Next i
StartPoint(0) = PointArray(0, TempIndex)
StartPoint(1) = PointArray(1, TempIndex)
BasePoint(0) = StartPoint(0)
BasePoint(1) = StartPoint(1)
CurPIndex = TempIndex
ReDim PointIndex(0)
PointIndex(0) = TempIndex
Direction = 1
BaseAngle = 270
TempAngle = 360
For i = 1 To N
For ii = 0 To N
If (ii = PointIndex(0) And CurPIndex PointIndex(0)) Or (ii CurPIndex And (Not IsIn(ii, PointIndex))) Then
SecendPoint(0) = PointArray(0, ii)
SecendPoint(1) = PointArray(1, ii)
Temp = GetAngle(BasePoint, SecendPoint, BaseAngle, Direction)
'Print #1, CurPIndex & "," & ii & ":" & Temp
If Temp BasePoint(1) Then
Angle = 90
Else
Angle = -90
End If
Else
Angle = (Atn((SecendPoint(1) - BasePoint(1)) / (SecendPoint(0) - BasePoint(0)))) * 180 / Pi
End If
If SecendPoint(0) > BasePoint(0) Then
Angle = 360 + Angle '1,4
Else
Angle = 180 + Angle '2,3
End If
GetAngle = (Angle - BaseAngle) * Direction
If GetAngle
epdtdc0oqxs.jpg
|
|