第三次作业 三次Bezier曲线的绘制
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第三次作业三次Bezier曲线的绘制一.解题思路:
Bezier曲线是用N+1个顶点(控制点)所构成的N根折线来定义一根N阶曲线。本次作业中的三次Bezier曲线有4个顶点,设它们分别为P0,P1,P2,P3,那么对于曲线上各个点Pi(x,y)满足下列关系:
x=x0*1-u)*(1-u)*(1-u)+x1 *3*u*(1-u)*(1-u)+x2 *3*u*u*(1-u)+x3 *t*t*t
y=y0*(1-u)*(1-u)*(1-t)+y1*3*u*(1-u)*(1-u)+y2*3*u*u*(1-u) +y3 *u*u*u
所以只要确定控制点的坐标,该曲线可通过编程即可绘制出来。
本题取的初始控制点为:p0(-600,100)、p1(-300,400)、p2(300,600)、p3(600,100)。还可以通过输入不同的控制点画出不同的三次Bezier曲线。
程序中有绘制曲线,清空,清屏,退出四个按钮,其中点击绘制曲线按钮可根据控制点绘制出相应的曲线;点击清空按钮则可以将已绘制的曲线清除;点击清屏按钮可以将输入文本框中的数据清除,以方便输入新的数据;点击退出按钮则退出程序。
二.程序代码
Function f()
Picture1.FontSize = 9
Picture1.Scale (-900, 1000)-(900, -1000)
Picture1.Line (-800, 0)-(800, 0)
Picture1.Line (0, 800)-(0, -800)
For i = -7 To 7
Picture1.Line (100 * i, 0)-(100 * i, 20)
Picture1.CurrentX = i * 100 - 50: Picture1.CurrentY = -5: Picture1.Print i * 100 Next i
For i = -7 To -1
Picture1.Line (0, 100 * i)-(20, 100 * i)
Picture1.CurrentX = -100: Picture1.CurrentY = 100 * i + 20: Picture1.Print i * 100 Next i
For i = 1 To 7
Picture1.Line (0, 100 * i)-(20, 100 * i)
Picture1.CurrentX = -100: Picture1.CurrentY = 100 * i + 20: Picture1.Print i * 100 Next i
End Function
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.ScaleWidth = 900
Picture1.ScaleHeight = 900
f
Text1.Text = -600: Text2.Text = 100: Text3.Text = -300: Text4.Text = 400
Text5.Text = 300: Text6.Text = 600: Text7.Text = 600: Text8.Text = 100
End Sub
Private Sub command1_Click()
x0 = Text1.Text: y0 = Text2.Text
X1 = Text3.Text: Y1 = Text4.Text
X2 = Text5.Text: Y2 = Text6.Text
X3 = Text7.Text: Y3 = Text8.Text
Picture1.FontSize = 18
Picture1.CurrentX = 800: Picture1.CurrentY = -5: Picture1.Print "X"
Picture1.CurrentX = 10: Picture1.CurrentY = 810: Picture1.Print "Y"
For t = 0 To 1 Step 0.001
x = x0 * (1 - t) * (1 - t) * (1 - t) + X1 * 3 * t * (1 - t) * (1 - t) + X2 * 3 * t * t * (1 - t) + X3 * t * t * t
y = y0 * (1 - t) * (1 - t) * (1 - t) + Y1 * 3 * t * (1 - t) * (1 - t) + Y2 * 3 * t * t * (1 - t) + Y3 * t * t * t
Picture1.CurrentX = x0 + 10: Picture1.CurrentY = y0 + 10: Picture1.Print "p0" Picture1.CurrentX = X1 + 10: Picture1.CurrentY = Y1 + 10: Picture1.Print "p1" Picture1.CurrentX = X2 + 10: Picture1.CurrentY = Y2 + 10: Picture1.Print "p2" Picture1.CurrentX = X3 + 10: Picture1.CurrentY = Y3 + 10: Picture1.Print "p3" Picture1.DrawWidth = 1
Picture1.Line (x0, y0)-(X1, Y1), vbBlue
Picture1.Line (X1, Y1)-(X2, Y2), vbBlue Picture1.Line (X2, Y2)-(X3, Y3), vbBlue Picture1.DrawWidth = 2
Picture1.PSet (x, y), vbRed
Next t
End Sub
Private Sub Command2_Click()
Picture1.Cls
f
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
三.运行结果截图