哪位高手知道点排序函数怎样使用啊?
转载自 123523058最终编辑 万事从渠马耳风
哪位高手知道点排序函数怎样使用啊?
PList是这样的数据吗?
PList(0 to 7)
PList(0)=123.01:PList(1)=451.0
PList(2)=126.01:PList(3)=411.0
PList(4)=128.01:PList(5)=481.0
PList(6)=144.01:PList(7)=471.0
这样我试验了一下,好像不行吗,请高手指点,谢谢!
函数如下:
'PList是一个点坐标的一维数组,按地址传递
'点排序(x坐标从小到大,y坐标从小到大)
Function DianPaiXu3(ByRef PList() As Variant)
Dim I As Long
I = UBound(PList)
Dim Pmin As Variant
Dim Temp As Double
Dim J As Long, K As Long, N As Long, M As Long
Dim P1 As Variant
Dim P2 As Variant
Dim P3 As Variant
'按x坐标排序
For J = 0 To I
For K = J + 1 To I
P1 = PList(J)
P2 = PList(K)
If P1(0) >= P2(0) Then
P3 = PList(J) '=P1
PList(J) = PList(K) 'p1=P2
PList(K) = P3 'P2 = P3
End If
Next K
Next J
'对x坐标相等的进行y坐标排序
For J = 0 To I
For K = 0 To I
P1 = PList(J)
P2 = PList(K)
If P1(0) = P2(0) Then
If P1(1) < P2(1) Then
P3 = PList(J) '=P1
PList(J) = PList(K) 'p1=P2
PList(K) = P3 'P2 = P3
End If
End If
Next K
Next J
End Function
'点排序(同一条直线上的点)
Function DianPaiXu1(ByRef PList() As Variant)
Dim I As Long
I = UBound(PList)
Dim M As Variant
Dim N As Variant
Dim J As Long
Dim L As Long
Dim Temp As Variant
For J = 1 To I
M = PList(J)
For L = J + 1 To I
N = PList(L)
If M(0) + M(1) > N(0) + N(1) Then
Temp = PList(J)
PList(J) = PList(L)
PList(L) = Temp
End If
Next
Next
End Function
'按x坐标排序
For J = 0 To I-1 step 2
For K = J + 1 To I step 2
页:
[1]