13461
幼苗
共回答了15个问题采纳率:93.3% 举报
这个函数还应该传入AB两点的坐标,才能计算
定义一个类型,便于表示坐标
private type ZB
x as integer
y as integer
end type
Private Sub Command1_Click()
Dim a As ZB
Dim b As ZB
Dim c As ZB
Dim jl As Single
a.x = 10
a.y = 10
b.x = 20
b.y = 20
jl = 5'AB间的距离,以B点向A点方向为正,在AB延长线上为负.
c = jszb(a, b, jl)
MsgBox "C的横坐标是:" c.x vbCrLf "C的纵坐标是:" c.y
End Sub
以上赋值只作示例用,可根据情况赋值.
赋值后调用下面的过程,可返回C的坐标.
Private Function jszb(a As ZB, b As ZB, s) As ZB
Dim ab As Single
Dim bl As Single
Dim c As ZB
ab = Sqr((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y))
bl = (ab - s) / ab
c.x = bl * (b.x - a.x) + a.x
c.y = bl * (b.y - a.y) + a.y
jszb = c
End Function
1年前
10