|
这样弄弄会更快一点,主要是减少For i = 2 To UBound(crr)中的计算量
Sub js3()
Dim i, j As Long
Dim arr, brr, crr, drr
Dim t As Double
Dim d1 As Double
Dim d2 As Double
Dim d3 As Double
Dim td As Double
Dim d As Double
Dim twc As Double
Dim imin As Long
Dim w As Double
Dim ZDK As Integer
tm = Timer
'''''''''''''进度条'''''''''''''''''''''''
'UserForm1.Show 0
'ZDK = UserForm1.TextBox1.Width
'UserForm1.TextBox2.SetFocus '焦点设置在文本框2防止闪烁
'''''''''''''进度条'''''''''''''''''''''''
arr = Sheet1.Range("d2:f" & Cells(Rows.Count, "f").End(xlUp).Row)
brr = Sheet1.Range("a2:c" & Cells(Rows.Count, "c").End(xlUp).Row)
t = Timer
ReDim crr(1 To UBound(brr), 1 To 3) As Double
ReDim drr(1 To UBound(arr), 1 To 4)
Dim b2 As Double, b3 As Double
For i = 1 To UBound(brr)
b2 = brr(i, 3) * PI
b3 = brr(i, 3) * PI
twc = Cos(b3)
crr(i, 1) = twc * Cos(b2)
crr(i, 2) = twc * Sin(b2)
crr(i, 3) = Sin(b3)
Next
Dim a2 As Double, a3 As Double, x As Double, y As Double, z As Double, iubc As Long, iuba As Long, p As Long, p0 As Double
iuba = UBound(arr)
iubc = UBound(crr)
p0 = 100 / iuba
For j = 1 To iuba
a2 = arr(j, 2) * PI
a3 = arr(j, 3) * PI
twc = Cos(a3)
d1 = twc * Cos(a2)
d2 = twc * Sin(a2)
d3 = Sin(a3)
x = d1 - crr(1, 1)
y = d2 - crr(1, 2)
z = d3 - crr(1, 3)
d = x * x + y * y + z * z
imin = 1
For i = 2 To iubc
x = d1 - crr(i, 1)
y = d2 - crr(i, 2)
z = d3 - crr(i, 3)
td = x * x + y * y + z * z
If td < d Then
d = td
imin = i
End If
Next
drr(j, 1) = brr(imin, 1)
drr(j, 2) = brr(imin, 2)
drr(j, 3) = brr(imin, 3)
'drr(j, 4) = CalcDistance(brr(imin, 3), brr(imin, 2), arr(j, 3), arr(j, 2))
drr(j, 4) = 6378137 * 2 * Application.Asin(Sqr(d) * 0.5)
'''''''''''进度条''''''''''''''''''''''
' If j * p0 > p + 5 Then
' p = j * p0
' UserForm1.Label1.Width = ZDK * p / 100
' UserForm1.Label2.Caption = p & "%"
DoEvents
' End If
'''''''''''进度条''''''''''''''''''''''
Next
Sheet1.Range("g2").Resize(UBound(arr), 4) = drr
Unload UserForm1
MsgBox "恭喜,计算完成" & ",耗时:" & Timer - tm, vbOKOnly Or 64, "提示"
End Sub
|
评分
-
1
查看全部评分
-
|