VB如何实现平滑曲线

我只有20个数,要在坐标系xOy中绘制,要求用平滑曲线(函数式未知)... 我只有20个数,要在坐标系xOy中绘制,要求用平滑曲线(函数式未知) 展开
 我来答
温柔_勩曀媳54
2014-07-03 · 超过54用户采纳过TA的回答
知道答主
回答量:164
采纳率:100%
帮助的人:48.7万
展开全部
VERSION 5.00 Begin VB.Form FrmMain AutoRedraw = -1 'True Caption = "光滑直线" ClientHeight = 6780 ClientLeft = 60 ClientTop = 450 ClientWidth = 9795 LinkTopic = "Form1" ScaleHeight = 452 ScaleMode = 3 'Pixel ScaleWidth = 653 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton CmdDraw Caption = "绘制" Height = 375 Left = 120 TabIndex = 0 Top = 120 Width = 1215 End Begin VB.Line Line1 Visible = 0 'False X1 = 48 X2 = 272 Y1 = 128 Y2 = 88 End End Attribute VB_Name = "FrmMain" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long Function Min(s1 As Long, s2 As Long) As Long If s1 < s2 Then Min = s1 Else Min = s2 End Function Function Max(s1 As Long, s2 As Long) As Long If s1 > s2 Then Max = s1 Else Max = s2 End Function Private Sub CmdDraw_Click() Dim Scal As Single, Gray As Long, MinX As Long, MaxX As Long, MinY As Long, MaxY As Long Dim X1 As Long, X2 As Long, Y1 As Long, Y2 As Long, X3 As Single, Y3 As Single Line1.Visible = False MinX = Min(Line1.X1, Line1.X2): MaxX = Max(Line1.X1, Line1.X2) MinY = Min(Line1.Y1, Line1.Y2): MaxY = Max(Line1.Y1, Line1.Y2) If (Line1.Y1 < Line1.Y2 And Line1.X1 < Line1.X2) Or (Line1.Y1 > Line1.Y2 And Line1.X1 > Line1.X2) Then If Abs(Line1.X1 - Line1.X2) > Abs(Line1.Y1 - Line1.Y2) Then Scal = Abs(Line1.Y2 - Line1.Y1) / Abs(Line1.X2 - Line1.X1) For i = 0 To MaxX - MinX Y3 = i * Scal + MinY: Y1 = Int(Y3): Y2 = Y1 + 1 Gray = (Y2 - Y3) * 255 SetPixel Me.hdc, i + MinX, Y2, RGB(Gray, Gray, Gray) Gray = (Y3 - Y1) * 255 SetPixel Me.hdc, i + MinX, Y1, RGB(Gray, Gray, Gray) Next i Else Scal = Abs(Line1.X2 - Line1.X1) / Abs(Line1.Y2 - Line1.Y1) For i = 0 To MaxY - MinY X3 = i * Scal + MinX: X1 = Int(X3): X2 = X1 + 1 Gray = (X2 - X3) * 255 SetPixel Me.hdc, X2, i + MinY, RGB(Gray, Gray, Gray) Gray = (X3 - X1) * 255 SetPixel Me.hdc, X1, i + MinY, RGB(Gray, Gray, Gray) Next i End If Else If Abs(Line1.X1 - Line1.X2) > Abs(Line1.Y1 - Line1.Y2) Then Scal = -Abs(Line1.Y2 - Line1.Y1) / Abs(Line1.X2 - Line1.X1) For i = 0 To MaxX - MinX Y3 = i * Scal + MaxY: Y1 = Int(Y3): Y2 = Y1 + 1 Gray = (Y2 - Y3) * 255 SetPixel Me.hdc, i + MinX, Y2, RGB(Gray, Gray, Gray) Gray = (Y3 - Y1) * 255 SetPixel Me.hdc, i + MinX, Y1, RGB(Gray, Gray, Gray) Next i Else Scal = -Abs(Line1.X2 - Line1.X1) / Abs(Line1.Y2 - Line1.Y1) For i = 0 To MaxY - MinY X3 = i * Scal + MaxX: X1 = Int(X3): X2 = X1 + 1 Gray = (X2 - X3) * 255 SetPixel Me.hdc, X2, i + MinY, RGB(Gray, Gray, Gray) Gray = (X3 - X1) * 255 SetPixel Me.hdc, X1, i + MinY, RGB(Gray, Gray, Gray) Next i End If End If Me.Refresh End Sub Private Sub Form_Load() Me.ScaleMode = vbPixels Me.AutoRedraw = True End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Line1.Visible = True Line1.X1 = x: Line1.Y1 = y End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = vbLeftButton Then Line1.X2 = x: Line1.Y2 = y End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) Line1.X2 = x: Line1.Y2 = y End Sub
宝宝DC71G
2014-07-03 · TA获得超过112个赞
知道答主
回答量:134
采纳率:0%
帮助的人:64.1万
展开全部
VB好久没用,不过我知道里面要画平滑曲线要用到一个函数。好象是Line.具体怎么写,我忘了,你自己查查。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式