zeng29 发表于 2003-12-14 11:14:00

[VBA]关于点阵非交叉连线问题的算法及实现(非穷举法).

问题的提出:
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=13701
代码:

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 CurPIndexPointIndex(0)) Or (iiCurPIndex 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 TempBasePoint(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

myfreemind 发表于 2003-12-14 18:08:00

试用了一下,图中的点是要展进去的吗?怎么运行程序以后要一个一个的选择点呢?

myfreemind 发表于 2003-12-14 18:16:00

图中的点可否环型连接?由外向内,顺时针或逆时针均可,这样的话就可以首尾相接而且不交叉!如图:

zeng29 发表于 2003-12-15 10:33:00

本程序要做的是 :1首尾相连;2点与点之间的连接;3不能交叉
所以3楼所示的图形是不符合的.(首尾连接必交叉)

myfreemind 发表于 2003-12-15 18:22:00


是这样,明白了!我想问一下,你的程序运行要选择点是怎么回事?不选择的话没有办法将图中的点连接起来吗?对于图中的点有什么要求没有?

zeng29 发表于 2003-12-15 18:27:00

点阵的连线,自然要先确定点阵的数据.(这里是根据操作者选择的点进行连接)
对选择的点没有要求.数量和位置由操作者拾取.

myfreemind 发表于 2003-12-15 18:36:00

明白了!!谢谢!

莫名 发表于 2003-12-15 23:25:00

这好象没有唯一的解!
页: [1]
查看完整版本: [VBA]关于点阵非交叉连线问题的算法及实现(非穷举法).