用vb怎么能把两点用光滑的曲线连接起来
1个回答
展开全部
Option Explicit
Dim Xi() As Single, Yi() As Single, u1(40000) As Single, v1(40000) As Single
Dim a() As Single, b() As Single, c() As Single, dx() As Single, dy() As Single
Dim qx() As Single, qy() As Single
Dim num As Integer
Dim ii As Long
Const PP = 100
Function hypot(ByVal X As Single, ByVal Y As Single)
hypot = Sqr(X ^ 2 + Y ^ 2)
End Function
Sub tspLine(ByVal n As Integer, ByVal ch As Integer, ByVal tx1 As Single, ByVal tx2 As Single, ByVal ty1 As Single, ByVal ty2 As Single)
Dim tt As Single, bx3 As Single, bx4 As Single, by3 As Single, by4 As Single
Dim cx As Single, cy As Single, t(100) As Single, px(100) As Single, py(100) As Single
Dim u(3) As Single, v(3) As Single, i As Integer
num = 0
For i = 1 To n
t(i) = hypot(Xi(i) - Xi(i - 1), Yi(i) - Yi(i - 1))
Next i
Select Case ch
Case 0 '抛物条件
u(0) = (Xi(1) - Xi(0)) / t(1): u(1) = (Xi(2) - Xi(1)) / t(2)
u(2) = (u(1) - u(0)) / (t(2) + t(1))
tx1 = u(0) - u(2) * t(1)
u(0) = (Yi(1) - Yi(0)) / t(1): u(1) = (Yi(2) - Yi(1)) / t(2)
u(2) = (u(1) - u(0)) / (t(2) + t(1))
ty1 = u(0) - u(2) * t(1)
u(0) = (Xi(n) - Xi(n - 1)) / t(n): u(1) = (Xi(n - 1) - Xi(n - 2)) / t(n - 1)
u(2) = (u(0) - u(1)) / (t(n) + t(n - 1))
tx2 = u(0) + u(2) * t(n)
u(0) = (Yi(n) - Yi(n - 1)) / t(n): u(1) = (Yi(n - 1) - Yi(n - 2)) / t(n - 1)
u(2) = (u(0) - u(1)) / (t(n) + t(n - 1))
ty2 = u(0) + u(2) * t(n)
Case 1 '夹持条件
a(0) = 1: c(0) = 0: dx(0) = tx1: dy(0) = ty1
a(n) = 1: b(n) = 0: dx(n) = tx2: dy(n) = ty2
Case 2 '自由条件
a(0) = 2: c(0) = 1
dx(0) = 3 * (Xi(1) - Xi(0)) / t(1): dy(0) = 3 * (Yi(1) - Yi(0)) / t(1)
a(n) = 2: b(n) = 1
dx(n) = 3 * (Xi(n) - Xi(n - 1)) / t(n): dy(n) = 3 * (Yi(n) - Yi(n - 1)) / t(n)
Case 3 '循环条件
a(0) = 2: c(0) = 1
dx(0) = 3 * (Xi(1) - Xi(0)) / t(1) - (t(1) * (Xi(2) - Xi(1)) / t(2) - Xi(1) + Xi(0)) / (t(1) + t(2))
dy(0) = 3 * (Yi(1) - Yi(0)) / t(1) - (t(1) * (Yi(2) - Yi(1)) / t(2) - Yi(1) + Yi(0)) / (t(1) + t(2))
a(n) = 2: b(n) = 1
dx(n) = 3 * (Xi(n) - Xi(n - 1)) / t(n)
dx(n) = dx(n) + (Xi(n) - Xi(n - 1) - t(n) * (Xi(n - 1) - Xi(n - 2)) / t(n - 1)) / (t(n) + t(n - 1))
dy(n) = 3 * (Yi(n) - Yi(n - 1)) / t(n)
dy(n) = dy(n) + (Yi(n) - Yi(n - 1) - t(n) * (Yi(n - 1) - Yi(n - 2)) / t(n - 1)) / (t(n) + t(n - 1))
End Select
'计算方程组系数阵和常数阵
For i = 1 To n - 1
a(i) = 2 * (t(i) + t(i + 1)): b(i) = t(i + 1): c(i) = t(i)
dx(i) = 3 * (t(i) * (Xi(i + 1) - Xi(i)) / t(i + 1) + t(i + 1) * (Xi(i) - Xi(i - 1)) / t(i))
dy(i) = 3 * (t(i) * (Yi(i + 1) - Yi(i)) / t(i + 1) + t(i + 1) * (Yi(i) - Yi(i - 1)) / t(i))
Next i
'采用追赶法解方程组
c(0) = c(0) / a(0)
For i = 1 To n - 1
a(i) = a(i) - b(i) * c(i - 1): c(i) = c(i) / a(i)
Next i
a(n) = a(n) - b(n) * c(i - 1)
qx(0) = dx(0) / a(0): qy(0) = dy(0) / a(0)
For i = 1 To n
qx(i) = (dx(i) - b(i) * qx(i - 1)) / a(i)
qy(i) = (dy(i) - b(i) * qy(i - 1)) / a(i)
Next i
px(n) = qx(n): py(n) = qy(n)
For i = n - 1 To 0 Step -1
px(i) = qx(i) - c(i) * px(i + 1)
py(i) = qy(i) - c(i) * py(i + 1)
Next i
'计算曲线上点的坐标
For i = 0 To n - 1
bx3 = (3 * (Xi(i + 1) - Xi(i)) / t(i + 1) - 2 * px(i) - px(i + 1)) / t(i + 1)
bx4 = ((2 * (Xi(i) - Xi(i + 1)) / t(i + 1) + px(i) + px(i + 1)) / t(i + 1)) / t(i + 1)
by3 = (3 * (Yi(i + 1) - Yi(i)) / t(i + 1) - 2 * py(i) - py(i + 1)) / t(i + 1)
by4 = ((2 * (Yi(i) - Yi(i + 1)) / t(i + 1) + py(i) + py(i + 1)) / t(i + 1)) / t(i + 1)
tt = 0
While (tt <= t(i + 1))
cx = Xi(i) + (px(i) + (bx3 + bx4 * tt) * tt) * tt
cy = Yi(i) + (py(i) + (by3 + by4 * tt) * tt) * tt
u1(num) = cx: v1(num) = cy: num = num + 1: tt = tt + 0.5
Wend
u1(num) = Xi(i + 1): v1(num) = Yi(i + 1): num = num + 1
Next i
End Sub
Private Sub Form_Load()
ReDim Xi(PP)
ReDim Yi(PP)
ReDim a(PP)
ReDim b(PP)
ReDim c(PP)
ReDim dx(PP)
ReDim dy(PP)
ReDim qx(PP)
ReDim qy(PP)
Dim i As Long
ii = 0
Picture1.Scale (-5, 450)-(16, 250)
Xi(0) = 1
Yi(0) = 306
Xi(1) = 2
Yi(1) = 409
Xi(2) = 3
Yi(2) = 306
Xi(3) = 4
Yi(3) = 409
Xi(4) = 5
Yi(4) = 306
Xi(5) = 6
Yi(5) = 409
Xi(6) = 7
Yi(6) = 306
Xi(7) = 8
Yi(7) = 409
Xi(8) = 9
Yi(8) = 306
Xi(9) = 10
Yi(9) = 409
Xi(10) = 11
Yi(10) = 306
Xi(11) = 12
Yi(11) = 409
Xi(12) = 13
Yi(12) = 306
Xi(13) = 14
Yi(13) = 409
For i = 1 To 13
Load Shape1(i)
Shape1(i).Visible = True
Next
Picture1.ForeColor = RGB(200, 200, 200)
Picture1.Line (Picture1.ScaleLeft, 0)-(Picture1.ScaleLeft + Picture1.ScaleWidth, 0)
Picture1.Line (0, Picture1.ScaleTop)-(0, Picture1.ScaleTop + Picture1.ScaleHeight)
Picture1.ForeColor = RGB(255, 0, 0)
For i = 0 To 13
Shape1(i).Left = Xi(i) - Shape1(i).Width / 2
Shape1(i).Top = Yi(i) + Shape1(i).Height / 2
Next i
For i = 0 To 3
Picture1.PSet (Xi(i), Yi(i))
Next i
tspLine 13, 2, 0, 0, 0, 0
Picture1.PSet (u1(0), v1(0))
For i = 1 To num - 1
Picture1.Line -(u1(i), v1(i))
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询