'计算坐标闭合差
reX(1) = Xb: reY(1) = Yb: Tedge = 0
For i = 2 To iStation
reX(i) = reX(i - 1) + detX(i - 1)
reY(i) = reY(i - 1) + detY(i - 1)
Tedge = Tedge + sEdge(i - 1)
Next i
If iType = 1 Then
detTX = reX(iStation) - Xc
detTY = reY(iStation) - Yc
Else
detTX = reX(iStation) - Xb
detTY = reY(iStation) - Yb
End If
detTT = Sqr(detTX * detTX + detTY * detTY)
text2.Text = text2.Text & "坐标闭合差:detX " & Format(detTX, "0.000") & " , detY " & Format(detTY, "0.000")
text2.Text = text2.Text & " , ddetTotal " & Format(detTT, "0.000") & vbCrLf
If Abs(detTT / Tedge) > 1 / 2000 Then
MsgBox "坐标闭合差超限!", , "计算终止"
text2.Text = text2.Text & "边长精度为1/" & Str(Fix(Tedge / detTT)) & "超过限差,计算终止!"
Exit Sub
End If
text2.Text = text2.Text & "边长精度为1/" & Str(Fix(Tedge / detTT)) & "附合要求。"
'改正坐标增量:以边长为权
text2.Text = text2.Text & "改正后的坐标增量:" & vbCrLf
For i = 1 To iStation - 1
detX(i) = detX(i) - sEdge(i) * detTX / Tedge
text2.Text = text2.Text & Format(detX(i), "0.000") & " , "
detY(i) = detY(i) - sEdge(i) * detTY / Tedge
text2.Text = text2.Text & Format(detY(i), "0.000") & " ; "
Next i
text2.Text = text2.Text & vbCrLf
'计算最后的坐标
text2.Text = text2.Text & "坐标计算结果:" & vbCrLf
For i = 2 To iStation
reX(i) = reX(i - 1) + detX(i - 1)
text2.Text = text2.Text & Format(reX(i - 1), "0.000") & " , "
reY(i) = reY(i - 1) + detY(i - 1)
text2.Text = text2.Text & Format(reY(i - 1), "0.000") & " ; "
Next i
text2.Text = text2.Text & Format(reX(i - 1), "0.000") & " , " & Format(reY(i - 1), "0.000") & vbCrLf & "计算结束!" & vbCrLf
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnuOpen_Click()
Dim i As Integer '循环变量
CDg1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CDg1.ShowOpen '打开对话框
strFileName = CDg1.FileName '获得选中的文件名和路径
Open strFileName For Input As #1 '打开文件
Input #1, iType, Xa, Ya, Xb, Yb '读入路线类型和前两个起算点坐标
Select Case iType
Case 0
text2.Text = text2.Text & " 这是一个闭合导线,已知点坐标为:" & vbCrLf
Case 1
text2.Text = text2.Text & " 这是一个附和导线,已知点坐标为:" & vbCrLf
Case 2
text2.Text = text2.Text & " 这是一个支导线,已知点坐标为:" & vbCrLf
End Select
text2.Text = text2.Text & Format(Xa, "0.000") & " , " & Format(Ya, "0.000") & " , " & Format(Xb, "0.000") & " , " & Format(Yb, "0.000") & vbCrLf
If iType = 1 Then '是否继续读起算坐标,要根据路线类型来判断
Input #1, Xc, Yc, Xd, Yd
text2.Text = text2.Text & Format(Xc, "0.000") & " , " & Format(Yc, "0.000") & " , " & Format(Xd, "0.000") & " , " & Format(Yd, "0.000") & vbCrLf
End If
Input #1, iStation '读入测站数,并用测站数定义数组大小
text2.Text = text2.Text & " 测站数为:" & Str(iStation) & "。因此,待定点个数为" & Str(iStation - 2) & "个。" & vbCrLf
ReDim sAngle(iStation) As Double, sdAngle(iStation + 1) As Double, sEdge(iStation - 1) As Double
ReDim detX(iStation - 1) As Double, detY(iStation - 1) As Double, reX(iStation) As Double, reY(iStation) As Double
Input #1, iAngleType
If iAngleType = 1 Then
text2.Text = text2.Text & " 观测的角度为左角,共" & Str(iStation) & "个:" & vbCrLf
Else
text2.Text = text2.Text & " 观测的角度为右角,共" & Str(iStation) & "个:" & vbCrLf
End If
For i = 1 To iStation '读入角度观测值
Input #1, sAngle(i)
text2.Text = text2.Text & Format(sAngle(i), "0.0000") & " , "
sAngle(i) = DoToHu(sAngle(i))
Next i
text2.Text = text2.Text & vbCrLf & Str(iStation - 1) & "个边长观测值为:" & vbCrLf
For i = 1 To iStation - 1 '读入边长观测值
Input #1, sEdge(i)
text2.Text = text2.Text & Format(sEdge(i), "0.000") & " , "
Next i
text2.Text = text2.Text & vbCrLf
Close #1 '不要忘记关闭文件
End Sub
Private Sub mnuSave_Click()
CDg1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
CDg1.ShowSave
strFileName = CDg1.FileName
Open strFileName For Output As #1
Print #1, " ====附合导线解算结果===="
detA = detA * iStation
Print #1, "角度闭合差:"; Format(HuToDo(detA), "0.0000"); ",角度限差:"; Str(Int(40 * Sqr(iStation))); "'',符合要求。"
Print #1, "坐标闭合差:X方向"; Format(detTX, "0.000"); ",Y方向"; Format(detTY, "+0.000"); ",精度1/"; Trim(Fix(Tedge / detTT)); ",符合要求。"
Dim ts As String, i%
For i = 1 To iStation
ts = ts & Format(sAngle(i), "0.0000") & ","
Next i
Print #1, "改正后的角度观测值:"; ts
ts = ""
For i = 1 To iStation + 1
ts = ts & Format(sdAngle(i), "0.0000") & ","
Next i
Print #1, "坐标方位角:"; ts
ts = ""
For i = 1 To iStation - 1
ts = ts & Format(sEdge(i), "0.000") & ","
Next i
Print #1, "边长观测值:"; ts
ts = ""
For i = 1 To iStation - 1
ts = ts & Format(detX(i), "0.000") & ","
Next i
Print #1, "改正后X增量值:"; ts
ts = ""
For i = 1 To iStation - 1
ts = ts & Format(detY(i), "0.000") & ","
Next i
Print #1, "改正后Y增量值:"; ts
ts = ""
For i = 1 To iStation
ts = ts & Format(reX(i), "0.000") & ","
Next i
Print #1, "结果X坐标:"; ts
ts = ""
For i = 1 To iStation
ts = ts & Format(reY(i), "0.000") & ","
Next i
Print #1, "结果Y坐标:"; ts
Print #1, " ――计算者:×××"
Print #1, " ——检核者:×××"
Print #1, " ――――――――附合导线解算结果输出完毕"
Close #1
End Sub
'求AB的坐标方位角,输出的是弧度值
Public Function DirectAB(Xa#, Ya
#, Xb#, Yb#) As Double
Dim detX#, detY
#, tana#detX = Xb - Xa
detY = Yb - Ya
If Abs(detX) < 0.000001 Then
If detY > 0 Then
DirectAB = PI / 2
Else
DirectAB = PI * 3 / 2
End If
Else
tana = detY / detX
DirectAB = Atn(tana)
If detX < 0 Then
DirectAB = PI + DirectAB
ElseIf detX > 0 And detY < 0 Then
DirectAB = PI * 2 + DirectAB
End If
End If
End Function
'弧度化为度.分秒的形式:输入弧度值,输出度.分秒(各占两位)
Public Function HuToDo(ByVal Hu As Double) As Single
Dim du%, fen%, miao%
Hu = Hu * 180 / PI
du = Fix(Hu)
Hu = (Hu - du) * 60
fen = Fix(Hu)
Hu = (Hu - fen) * 60
miao = Fix(Hu + 0.5)
If miao = 60 Then
fen = fen + 1
miao = 0
End If
HuToDo = du + fen / 100 + miao / 10000
End Function
'将度.分秒形式化为弧度:输入为度.分秒形式,输出为弧度
Public Function DoToHu(ByVal DoFenMiao As Double) As Single
Dim du%, fen%, miao%, angle#
du = Fix(DoFenMiao)
DoFenMiao = (DoFenMiao - du) * 100
fen = Fix(DoFenMiao)
miao = (DoFenMiao - fen) * 100
angle = du + fen / 60 + miao / 3600
DoToHu = angle * PI / 180
End Function