首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么在VB中画曲线

2012-01-06 
如何在VB中画曲线 已知几个点如何将这几个点连接成一条平滑的曲线?[解决办法]在picture控件中调用line方法

如何在VB中画曲线

已知几个点    
如何将这几个点连接成一条平滑的曲线?

[解决办法]
在picture控件中调用line方法就可以了 不过要先设定好picture的坐标
[解决办法]
Private Sub ShiftBuf(ByVal PicIdx As Integer)
Dim i As Integer

If PicIdx = 1 Then
For i = 1 To DataNo - 1 'Left Shift these buffers
If fABuf(i + 1) <> -100 Then
fABuf(i) = fABuf(i + 1)
End If
Next
Else
For i = 1 To DataNo - 1 'Left Shift these buffers
If fTBuf(i + 1) <> -100 Then
fTBuf(i) = fTBuf(i + 1)
End If
Next
End If
End Sub

Private Sub DrawPic(ByVal PicIdx As Integer)
Dim i As Integer

If PicIdx = 1 Then
'Set the scale of picture1
Picture1.Scale (0, fAMin - 1)-(DataNo, fAMax + 1)
'set the Max/Min/Middle value
lAMax.Caption = fAMax + 1
lAMin.Caption = fAMin - 1
lAMid.Caption = (fAMax + fAMin) / 2
'Clear these picture
Picture1.Cls
'Draw the middle line
Picture1.ForeColor = &HFF00FF
Picture1.Line (1, lAMid.Caption)-(DataNo - 1, lAMid.Caption)
'Draw values as lines
Picture1.ForeColor = &HFF
For i = 1 To DataNo - 1
If fABuf(i) <> -100 Then
If fABuf(i - 1) = -100 Then
Picture1.PSet (i, fAMax - fABuf(i))
Else
Picture1.Line -(i, fAMax - fABuf(i))
End If
End If
DoEvents
Next i
Else
'Set the scale of picture2
Picture2.Scale (0, fTMin - 1)-(DataNo, fTMax + 1)
'set the Max/Min/Middle value
lTMax.Caption = fTMax + 1
lTMin.Caption = fTMin - 1
lTMid.Caption = (fTMax + fTMin) / 2
'Clear these picture
Picture2.Cls
'Draw the middle line
Picture2.ForeColor = &HFF00FF
Picture2.Line (1, lTMid.Caption)-(DataNo - 1, lTMid.Caption)
'Draw values as lines
Picture2.ForeColor = &HFF
For i = 1 To DataNo - 1
If fTBuf(i) <> -100 Then
If fTBuf(i - 1) = -100 Then
Picture2.PSet (i, fTMax - fTBuf(i))
Else
Picture2.Line -(i, fTMax - fTBuf(i))
End If
End If
DoEvents
Next i
End If

End Sub
[解决办法]
数学问题!你必须知道曲线拟合方面的知识
[解决办法]
给你一段通过三次样条函数绘制光滑曲线的程序,我做的是7个点.

本人有个项目其中需要根据7个点生成一条连续光滑曲线,把算法发上来供大家参考。


'三次样条插值函数
'根据7个点插值形成一条连续曲线,该曲线由6段组成,连续光滑,2阶可导.

'yy0-yy6 给定点的纵坐标
'xx0-xx6 给定点的横坐标
'h,p,dd,aa,bb,mm都是中间过程,ff1-ff6是6条曲线的函数
'原算法你自己查吧,给你发过去挺不容易的,我也是看书,把算法简化后写的程序,你
'可以根据规律直接加减点数.

'其实算法很简单的,不用求导的.
'祝你好运


xx0 = (228 - 38.92157763 * Log(0.007 * 500) + b) * skp
xx1 = (228 - 38.92157763 * Log(0.01 * 500) + b) * skp
xx2 = (228 - 38.92157763 * Log(0.025 * 500) + b) * skp
xx3 = (228 - 38.92157763 * Log(0.05 * 500) + b) * skp


xx4 = (228 - 38.92157763 * Log(0.1 * 500) + b) * skp
xx5 = (228 - 38.92157763 * Log(0.25 * 500) + b) * skp
xx6 = (228 - 38.92157763 * Log(0.5 * 500) + b) * skp


h1 = xx1 - xx0
h2 = xx2 - xx1
h3 = xx3 - xx2
h4 = xx4 - xx3
h5 = xx5 - xx4
h6 = xx6 - xx5

p1 = (yy1 - yy0) / h1
p2 = (yy2 - yy1) / h2
p3 = (yy3 - yy2) / h3
p4 = (yy4 - yy3) / h4
p5 = (yy5 - yy4) / h5
p6 = (yy6 - yy5) / h6

dd1 = 6 * (p2 - p1)
dd2 = 6 * (p3 - p2)
dd3 = 6 * (p4 - p3)
dd4 = 6 * (p5 - p4)
dd5 = 6 * (p6 - p5)

aa1 = 2 * (h1 + h2)
aa2 = 2 * (h2 + h3) - h2 * h2 / aa1
aa3 = 2 * (h3 + h4) - h3 * h3 / aa2
aa4 = 2 * (h4 + h5) - h4 * h4 / aa3
aa5 = 2 * (h5 + h6) - h5 * h5 / aa4

bb1 = dd1
bb2 = dd2 - h2 * bb1 / aa1
bb3 = dd3 - h3 * bb2 / aa2
bb4 = dd4 - h4 * bb3 / aa3
bb5 = dd5 - h5 * bb4 / aa4

mm5 = bb5 / aa5
mm4 = (bb4 - h5 * mm5) / aa4
mm3 = (bb3 - h4 * mm4) / aa3
mm2 = (bb2 - h3 * mm3) / aa2
mm1 = (bb1 - h2 * mm2) / aa1
mm6 = 0
mm0 = 0

ff1 = (mm0 / (6 * h1)) * ((xx1 - xxx) ^ 3) + (mm1 / (6 * h1)) * ((xxx - xx0) ^ 3) + ((yy0 - mm0 * h1 * h1 / 6) / h1) * (xx1 - xxx) + ((yy1 - mm1 * h1 * h1 / 6) / h1) * (xxx - xx0)
ff2 = (mm1 / (6 * h2)) * ((xx2 - xxx) ^ 3) + (mm2 / (6 * h2)) * ((xxx - xx1) ^ 3) + ((yy1 - mm1 * h2 * h2 / 6) / h2) * (xx2 - xxx) + ((yy2 - mm2 * h2 * h2 / 6) / h2) * (xxx - xx1)
ff3 = (mm2 / (6 * h3)) * ((xx3 - xxx) ^ 3) + (mm3 / (6 * h3)) * ((xxx - xx2) ^ 3) + ((yy2 - mm2 * h3 * h3 / 6) / h3) * (xx3 - xxx) + ((yy3 - mm3 * h3 * h3 / 6) / h3) * (xxx - xx2)
ff4 = (mm3 / (6 * h4)) * ((xx4 - xxx) ^ 3) + (mm4 / (6 * h4)) * ((xxx - xx3) ^ 3) + ((yy3 - mm3 * h4 * h4 / 6) / h4) * (xx4 - xxx) + ((yy4 - mm4 * h4 * h4 / 6) / h4) * (xxx - xx3)
ff5 = (mm4 / (6 * h5)) * ((xx5 - xxx) ^ 3) + (mm5 / (6 * h5)) * ((xxx - xx4) ^ 3) + ((yy4 - mm4 * h5 * h5 / 6) / h5) * (xx5 - xxx) + ((yy5 - mm5 * h5 * h5 / 6) / h5) * (xxx - xx4)
ff6 = (mm5 / (6 * h6)) * ((xx6 - xxx) ^ 3) + (mm6 / (6 * h6)) * ((xxx - xx5) ^ 3) + ((yy5 - mm5 * h6 * h6 / 6) / h6) * (xx6 - xxx) + ((yy6 - mm6 * h6 * h6 / 6) / h6) * (xxx - xx5)

热点排行