求一段VB.net画曲线的代码?
比如说已知X=1.3,3.4,6.5,8,9.85,12.15对应的Y=4,4.8,6.2,7.7,7.4,7就像这样点的,如何画一个XY坐标系,然后根据这些点生成一条曲...
比如说已知X=1.3 , 3.4 , 6.5 , 8 , 9.85 , 12.15
对应的Y=4 , 4.8 , 6.2 , 7.7 , 7.4 , 7
就像这样点的,如何画一个XY坐标系,然后根据这些点生成一条曲线来?不是折线!可以发到我的邮箱 zzahkj@163.com 谢谢 展开
对应的Y=4 , 4.8 , 6.2 , 7.7 , 7.4 , 7
就像这样点的,如何画一个XY坐标系,然后根据这些点生成一条曲线来?不是折线!可以发到我的邮箱 zzahkj@163.com 谢谢 展开
3个回答
展开全部
给你个参考,是VB6的:
Option Explicit
'定义一个点
Private Type POINT
x As Integer
y As Integer
End Type
'定义控制点序列(最多100个)
Dim PList(100) As POINT
'给定PNum个控制点, 画n-3条B样条曲线
Private Sub printBLine(PNum As Integer)
Dim p0 As POINT
Dim p1 As POINT
Dim p2 As POINT
Dim p3 As POINT
If PNum < 4 Then Exit Sub
Dim i As Integer
'画控制点连线(PNum-1条)
For i = 0 To PNum - 2
Line (PList(i).x, PList(i).y)-(PList(i + 1).x, PList(i + 1).y), vbBlue
Next i
'画曲线(PNum-3条)
For i = 0 To PNum - 4
p0.x = PList(i).x
p0.y = PList(i).y
p1.x = PList(i + 1).x
p1.y = PList(i + 1).y
p2.x = PList(i + 2).x
p2.y = PList(i + 2).y
p3.x = PList(i + 3).x
p3.y = PList(i + 3).y
printBLine_Part p0, p1, p2, p3
Next i
End Sub
'给定4个控制点画一段样条曲线
Private Sub printBLine_Part( _
p0 As POINT, _
p1 As POINT, _
p2 As POINT, _
p3 As POINT _
)
Dim t As Double
Dim t3 As Double
Dim t2 As Double
Dim x As Integer
Dim y As Integer
For t = 0 To 1 Step 0.001
t3 = t * t * t
t2 = t * t
x = 0
y = 0
x = x + (-t3 + 3 * t2 - 3 * t + 1) * p0.x / 6
y = y + (-t3 + 3 * t2 - 3 * t + 1) * p0.y / 6
x = x + (3 * t3 - 6 * t2 + 4) * p1.x / 6
y = y + (3 * t3 - 6 * t2 + 4) * p1.y / 6
x = x + (-3 * t3 + 3 * t2 + 3 * t + 1) * p2.x / 6
y = y + (-3 * t3 + 3 * t2 + 3 * t + 1) * p2.y / 6
x = x + (t3) * p3.x / 6
y = y + (t3) * p3.y / 6
PSet (x, y), vbGreen
Next t
End Sub
Private Sub cmdPrint_Click()
Dim i As Integer
'给定6个控制点
PList(0).x = 1.3 * Me.ScaleWidth / 20
PList(0).y = 4 * Me.ScaleHeight / 20
PList(1).x = 3.4 * Me.ScaleWidth / 20
PList(1).y = 4.8 * Me.ScaleHeight / 20
PList(2).x = 6.5 * Me.ScaleWidth / 20
PList(2).y = 6.2 * Me.ScaleHeight / 20
PList(3).x = 8 * Me.ScaleWidth / 20
PList(3).y = 7.7 * Me.ScaleHeight / 20
PList(4).x = 9.85 * Me.ScaleWidth / 20
PList(4).y = 7.4 * Me.ScaleHeight / 20
PList(5).x = 12.15 * Me.ScaleWidth / 20
PList(5).y = 7 * Me.ScaleHeight / 20
printBLine 6
For i = 0 To 5
PSet (PList(i).x - 1, PList(i).y - 1), vbRed
PSet (PList(i).x - 1, PList(i).y), vbRed
PSet (PList(i).x, PList(i).y - 1), vbRed
PSet (PList(i).x, PList(i).y), vbRed
Next
'
' '给定6个控制点
' '本例中给的6个点满足循环使用控制点来取封闭
' PList(0).x = 100
' PList(0).y = 166
'
' PList(1).x = 500
' PList(1).y = 166
'
' PList(2).x = 200
' PList(2).y = 366
'
' PList(3).x = 100
' PList(3).y = 166
'
' PList(4).x = 500
' PList(4).y = 166
'
' PList(5).x = 200
' PList(5).y = 366
'
'' printBLine 6
End Sub
Option Explicit
'定义一个点
Private Type POINT
x As Integer
y As Integer
End Type
'定义控制点序列(最多100个)
Dim PList(100) As POINT
'给定PNum个控制点, 画n-3条B样条曲线
Private Sub printBLine(PNum As Integer)
Dim p0 As POINT
Dim p1 As POINT
Dim p2 As POINT
Dim p3 As POINT
If PNum < 4 Then Exit Sub
Dim i As Integer
'画控制点连线(PNum-1条)
For i = 0 To PNum - 2
Line (PList(i).x, PList(i).y)-(PList(i + 1).x, PList(i + 1).y), vbBlue
Next i
'画曲线(PNum-3条)
For i = 0 To PNum - 4
p0.x = PList(i).x
p0.y = PList(i).y
p1.x = PList(i + 1).x
p1.y = PList(i + 1).y
p2.x = PList(i + 2).x
p2.y = PList(i + 2).y
p3.x = PList(i + 3).x
p3.y = PList(i + 3).y
printBLine_Part p0, p1, p2, p3
Next i
End Sub
'给定4个控制点画一段样条曲线
Private Sub printBLine_Part( _
p0 As POINT, _
p1 As POINT, _
p2 As POINT, _
p3 As POINT _
)
Dim t As Double
Dim t3 As Double
Dim t2 As Double
Dim x As Integer
Dim y As Integer
For t = 0 To 1 Step 0.001
t3 = t * t * t
t2 = t * t
x = 0
y = 0
x = x + (-t3 + 3 * t2 - 3 * t + 1) * p0.x / 6
y = y + (-t3 + 3 * t2 - 3 * t + 1) * p0.y / 6
x = x + (3 * t3 - 6 * t2 + 4) * p1.x / 6
y = y + (3 * t3 - 6 * t2 + 4) * p1.y / 6
x = x + (-3 * t3 + 3 * t2 + 3 * t + 1) * p2.x / 6
y = y + (-3 * t3 + 3 * t2 + 3 * t + 1) * p2.y / 6
x = x + (t3) * p3.x / 6
y = y + (t3) * p3.y / 6
PSet (x, y), vbGreen
Next t
End Sub
Private Sub cmdPrint_Click()
Dim i As Integer
'给定6个控制点
PList(0).x = 1.3 * Me.ScaleWidth / 20
PList(0).y = 4 * Me.ScaleHeight / 20
PList(1).x = 3.4 * Me.ScaleWidth / 20
PList(1).y = 4.8 * Me.ScaleHeight / 20
PList(2).x = 6.5 * Me.ScaleWidth / 20
PList(2).y = 6.2 * Me.ScaleHeight / 20
PList(3).x = 8 * Me.ScaleWidth / 20
PList(3).y = 7.7 * Me.ScaleHeight / 20
PList(4).x = 9.85 * Me.ScaleWidth / 20
PList(4).y = 7.4 * Me.ScaleHeight / 20
PList(5).x = 12.15 * Me.ScaleWidth / 20
PList(5).y = 7 * Me.ScaleHeight / 20
printBLine 6
For i = 0 To 5
PSet (PList(i).x - 1, PList(i).y - 1), vbRed
PSet (PList(i).x - 1, PList(i).y), vbRed
PSet (PList(i).x, PList(i).y - 1), vbRed
PSet (PList(i).x, PList(i).y), vbRed
Next
'
' '给定6个控制点
' '本例中给的6个点满足循环使用控制点来取封闭
' PList(0).x = 100
' PList(0).y = 166
'
' PList(1).x = 500
' PList(1).y = 166
'
' PList(2).x = 200
' PList(2).y = 366
'
' PList(3).x = 100
' PList(3).y = 166
'
' PList(4).x = 500
' PList(4).y = 166
'
' PList(5).x = 200
' PList(5).y = 366
'
'' printBLine 6
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用Microsoft Chart控件
追问
这个控件能画平滑曲线吗?
追答
不能
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询