📄 坐标转换.frm
字号:
VERSION 5.00
Begin VB.Form frmzhbzh
BorderStyle = 3 'Fixed Dialog
Caption = "坐标转换"
ClientHeight = 5115
ClientLeft = 45
ClientTop = 330
ClientWidth = 6180
Icon = "坐标转换.frx":0000
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5115
ScaleWidth = 6180
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame5
Caption = "要求计算"
Height = 1095
Left = 0
TabIndex = 22
Top = 1560
Width = 2295
Begin VB.OptionButton Option2
Caption = "相对坐标转换原坐标"
Height = 255
Left = 120
TabIndex = 4
Top = 720
Width = 2055
End
Begin VB.OptionButton Option1
Caption = "原坐标转换相对坐标"
Height = 255
Left = 120
TabIndex = 3
Top = 360
Width = 2055
End
End
Begin VB.Frame Frame4
Caption = "计算结果"
Height = 4575
Left = 2400
TabIndex = 17
Top = 40
Width = 3735
Begin VB.ListBox List1
Height = 4200
Left = 120
TabIndex = 23
Top = 240
Width = 3495
End
End
Begin VB.Frame Frame3
Caption = "在相对坐标"
Height = 1095
Left = 0
TabIndex = 16
Top = 3960
Width = 2295
Begin VB.TextBox Text7
Height = 270
Left = 1200
TabIndex = 8
Text = "Text7"
Top = 720
Width = 975
End
Begin VB.TextBox Text6
Height = 270
Left = 1200
TabIndex = 7
Text = "Text6"
Top = 360
Width = 975
End
Begin VB.Label Label7
Caption = "坐标 Y="
Height = 255
Left = 120
TabIndex = 21
Top = 720
Width = 1335
End
Begin VB.Label Label6
Caption = "坐标 X="
Height = 255
Left = 120
TabIndex = 20
Top = 360
Width = 1335
End
End
Begin VB.Frame Frame2
Caption = "在原坐标"
Height = 1095
Left = 0
TabIndex = 15
Top = 2760
Width = 2295
Begin VB.TextBox Text5
Height = 270
Left = 1200
TabIndex = 6
Text = "Text5"
Top = 720
Width = 975
End
Begin VB.TextBox Text4
Height = 270
Left = 1200
TabIndex = 5
Text = "Text4"
Top = 360
Width = 975
End
Begin VB.Label Label5
Caption = "坐标 Y="
Height = 255
Left = 120
TabIndex = 19
Top = 720
Width = 1335
End
Begin VB.Label Label4
Caption = "坐标 X="
Height = 255
Left = 120
TabIndex = 18
Top = 360
Width = 1095
End
End
Begin VB.CommandButton Command2
Caption = "关闭"
Height = 375
Left = 5280
TabIndex = 10
Top = 4680
Width = 855
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 4320
TabIndex = 9
Top = 4680
Width = 855
End
Begin VB.Frame Frame1
Caption = "相对原坐标"
Height = 1455
Left = 0
TabIndex = 11
Top = 40
Width = 2295
Begin VB.TextBox Text3
Height = 270
Left = 1200
TabIndex = 2
Text = "Text3"
Top = 1080
Width = 975
End
Begin VB.TextBox Text2
Height = 270
Left = 1200
TabIndex = 1
Text = "Text2"
Top = 720
Width = 975
End
Begin VB.TextBox Text1
Height = 270
Left = 1200
TabIndex = 0
Text = "Text1"
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "逆时针转θ="
Height = 255
Left = 120
TabIndex = 14
Top = 1080
Width = 1095
End
Begin VB.Label Label2
Caption = "向上平移B0="
Height = 255
Left = 120
TabIndex = 13
Top = 720
Width = 1215
End
Begin VB.Label Label1
Caption = "向右平移A0="
Height = 255
Left = 120
TabIndex = 12
Top = 360
Width = 1455
End
End
End
Attribute VB_Name = "frmzhbzh"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim xm, ym, x, y As Double
Private Sub Command1_Click()
'计算
On Error GoTo handlerror
a0 = Val(Text1.Text)
b0 = Val(Text2.Text)
ct = Val(Text3.Text)
du = Int(ct)
fen = Int((ct - du) * 100)
miao = (ct - du - fen / 100) * 10000
dus = du + fen / 60 + miao / 3600
hud = dus * pi / 180
If Option1.Value = True Then '原点转换为相对坐标
xm = Val(Text4.Text)
ym = Val(Text5.Text)
x1 = (xm - a0) * Cos(hud) + (ym - b0) * Sin(hud)
y1 = -(xm - a0) * Sin(hud) + (ym - b0) * Cos(hud)
List1.AddItem ""
List1.AddItem " X0=" + Text4.Text + " Y0=" + Text5.Text
List1.AddItem " X1=" + Str(Int(x1 * 10000 + 0.5) / 10000) + " Y1=" + Str(Int(y1 * 10000 + 0.5) / 10000)
End If
If Option2.Value = True Then '相对坐标转换为原点
xm = Val(Text6.Text)
ym = Val(Text7.Text)
x = a0 + xm * Cos(hud) - ym * Sin(hud)
y = b0 + xm * Sin(hud) + ym * Cos(hud)
List1.AddItem ""
List1.AddItem " X'=" + Text6.Text + " Y'=" + Text7.Text
List1.AddItem " X =" + Str(Int(x * 10000 + 0.5) / 10000) + " Y =" + Str(Int(y * 10000 + 0.5) / 10000)
End If
Exit Sub
handlerror:
xianshi = MsgBox("请检查输入的数据后再试试。", vbInformation, "问题提示")
End Sub
Private Sub Command2_Click()
'关闭
On Error GoTo handlerror
If Text1.Text = "" And Text2.Text = "" And Text3.Text = "" Then
Unload Me
Exit Sub
End If
If List1.ListCount > 1 And rjsfzc = 88 Then
frmMain.Text1 = frmMain.Text1 & vbCrLf & ""
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 《坐标转换计算结果》:"
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 向右平移A0=" + Text1.Text
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 向上平移B0=" + Text2.Text
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 逆时针 θ=" + Text3.Text
If Option1.Value = True Then
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 原坐标转换相对坐标:"
End If
If Option2.Value = True Then
frmMain.Text1 = frmMain.Text1 & vbCrLf & " 相对坐标转换原坐标:"
End If
For i = 0 To List1.ListCount - 1
frmMain.Text1 = frmMain.Text1 & vbCrLf & List1.List(i)
Next i
frmMain.Text1 = frmMain.Text1 & vbCrLf & " --------------------------------------"
End If
Unload Me
Exit Sub
handlerror:
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'Esc键退出,VbEscape可以用27代替
On Error GoTo handlerror
If KeyAscii = 27 Then
Unload Me
End If
Exit Sub
handlerror:
End Sub
Private Sub Form_Load()
'启动
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
List1.Clear
List1.AddItem "单位:"
List1.AddItem " 长度为米"
List1.AddItem " 角度为°′″"
List1.AddItem " 如23°15′45″按23.1545输入"
List1.AddItem " 逆时针为正、顺时针为负"
End Sub
Private Sub Option1_Click()
'原点转换相对坐标
Frame2.Visible = True
Frame3.Visible = False
List1.Clear
End Sub
Private Sub Option2_Click()
'相对坐标转换原坐标
Frame2.Visible = False
Frame3.Visible = True
List1.Clear
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -