‘壹’ 用vb编程已知平面坐标系中两点的坐标,求两点的距离
Const e As Double = 0.000001Sub jisuan(x1 As Long,y1 As Long,x2 As Long,y2 As Long)c1 = Val(Str(x2 - x1))c2 = Val(Str(y2 - y1))Dim x As Doublex = c1 * c1 + c2 * c2Dim d1 As Double,d2 As Doubled1 = x /...
‘贰’ 用vb编程已知平面坐标系中两点的坐标,求两点的距离
Private Sub Command1_Click()
Dim x1 As Single, x2 As Single, y1 As Single, y2 As Single, s As Single
x1 = InputBox("x1", "输入x1")
y1 = InputBox("y1", "输入y1")
x2 = InputBox("x2", "输入x2")
y2 = InputBox("y2", "输入y2")
s = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
Print "两点间距离为"; s
End Sub
‘叁’ vb编程实现已知A,B两点三维坐标和AB连线上C点到A点距离如何求C点坐标
以下程序采用的是向量求法(程序中完善了一些小细节)
PrivateSubcal_Click()'计算程序
DimLab
Dimm,a
IfXa.Text=""OrXb.Text=""OrYa.Text=""OrYb.Text=""OrZa.Text=""OrZb.Text=""OrLac.Text=""Then
a=MsgBox("请输入正确的参数",1,"返回")
clear
Else
Lab=((Xb.Text-Xa.Text)^2+(Yb.Text-Ya.Text)^2+(Zb.Text-Za.Text)^2)^0.5'求AB的模(即AB的长度)
m=Lac.Text/Lab
Xc.Text=m*(Xb.Text-Xa.Text)+Xa.Text
Yc.Text=m*(Yb.Text-Ya.Text)+Ya.Text
Zc.Text=m*(Zb.Text-Za.Text)+Za.Text
EndIf
EndSub
PrivateSubclear()'清除画面数据
Xa.Text=""
Ya.Text=""
Za.Text=""
Xb.Text=""
Yb.Text=""
Zb.Text=""
Xc.Text=""
Yc.Text=""
Zc.Text=""
Lac.Text=""
EndSub
PrivateSubclr_Click()'清除按钮程序
clear
EndSub
向量原理
‘肆’ 如何利用vb,编写一个程序,求平面中两点之间的距离
点1我们叫A吧,它的坐标(X1,Y1),点2我们叫B吧,它的坐标(X2,Y2),那么AB之间的距离是:
S=SQR((X1-X2)^2+(Y1-Y2)^2)
勾股定律!
‘伍’ 用VB程序设计计算两经度之间的距离,题目如下,在线等。
Private Sub Command1_Click()
If Text1.Text <> "" Then
a = Val(Text1.Text)
Else
a = -Val(Text2.Text)
End If
If Text3.Text <> "" Then
b = Val(Text3.Text)
Else
b = -Val(Text4.Text)
End If
c = Abs(a - b)
If c > 180 Then c = 360 - c
Text5.Text = c * 2 * 3.1415926 * 6378.137 / 360
End Sub
‘陆’ VB 实现测量窗体上两点之间的距离
Dimx1AsSingle,y1AsSingle,x2AsSingle,y2AsSingle,mAsSingle,nAsSingle,LAsSingle
PrivateSubForm_Load()
Line1.Visible=False
EndSub
PrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
x1=X
y1=Y
EndIf
EndSub
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
Line1.x1=x1
Line1.y1=y1
Line1.x2=X
Line1.y2=Y
Line1.Visible=True
EndIf
EndSub
PrivateSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
IfButton=1Then
Line1.Visible=False
x2=X
y2=Y
Ifm=0Then
m=Me.ScaleX(Sqr((x2-x1)^2+(y2-y1)^2),1,3)
MsgBox"标尺的像素长度m="&m
ElseIfn=0Then
n=Me.ScaleX(Sqr((x2-x1)^2+(y2-y1)^2),1,3)
L=5*n/m
MsgBox"两点之间的像素长度n="&n&vbCrLf&"两点之间的标尺距离L="&L&"mm"
m=0
n=0
L=0
EndIf
EndIf
EndSub
上述代码用到的唯一一个控件是Line1
‘柒’ VB计算两点间的距离
Private Sub Command1_Click()
Dim x1 As Integer
Dim x2 As Integer
Dim y1 As Integer
Dim y2 As Integer
Dim Sk As Double
Dim Sl As Long
On Error GoTo errorsorryl
x1 = CInt(InputBox("输入 x1 数据: "))
y1 = CInt(InputBox("输入 y1 数据: "))
x2 = CInt(InputBox("输入 x2 数据: "))
y2 = CInt(InputBox("输入 y2 数据: "))
Sl = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)
If Sl > 0 Then
Sk = Sqr(Sl)
MsgBox "你输入的数据最后的计算结果为:" & Sk, vbOKOnly, "提示"
Exit Sub
Else
MsgBox "你输入的数据有错误,请从新确认后再输入……", vbOKOnly, "警告"
End If
errorsorryl:
MsgBox "你输入的数据有错误,请从新确认后再输入……", vbOKOnly, "警告"
End Sub
Private Sub Form_Load()
Text1.Text = ""
Me.Show
Command1.SetFocus
End Sub
一个command控件
‘捌’ 求VB 基础操作 已知平面坐标系内两点的坐标,求两点间的距离
新建一个form1
在form1中加入5个textbox(分别是:text1、text2、text3、text4、text5)
在form1下写入如下代码:
PrivateSubCommand1_Click()
Text5.Text=((Val(Text1.Text)-Val(Text3.Text))^2+(Val(Text2.Text)-Val(Text4.Text))^2)^0.5
EndSub
PrivateSubForm_Load()
Text1.Text="点A的X"
Text2.Text="点A的Y"
Text3.Text="点B的X"
Text4.Text="点B的Y"
Text5.Text="距离"
EndSub
‘玖’ vb编程怎么输入坐标值并求两座标间的距离
屏幕width—(y1 + y2)=距离
屏幕height—.........=距离2
距离1=y
距离2=x