您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 其它文档 > 计算机图形学实验报告-实验3Bezier曲线
1计算机图形学实验报告班级计算机工硕班学号2011220456姓名王泽晶2实验三:Bezier曲线实验目的:通过本次试验,学生可以掌握Bezier曲线的求值、升阶算法及Bezier曲线绘制方法。实验内容:1.绘制控制多边形(使用鼠标左键指定多边形顶点,右键结束),使用白色折线段表示。2.绘制Bezier曲线,使用红色,线宽为2,在右键结束控制多边形顶点指定时即执行。Bezier曲线是一种广泛应用于外形设计的参数曲线,它通过对一些特定点的控制来控制曲线的形状,我们称这些点为控制顶点。现在我们来给出Bezier曲线的数学表达式。在空间给定1n个点012,,,,nPPPP,称下列参数曲线为n次Bezier曲线:,0()(),01niiniPtPBtt其中,()inBt是Bernstein基函数,其表达式为:,!()(1)!()!iniinnBtttini,接着我们讨论3次Bezier曲线,我们也采用将表达式改写为矩阵形式的方法,我们得到:3303!()(1)!(3)!iiiiPtPttii32230123(1)3(1)3(1)tPttPttPtP01323232323331,363,33,PPtttttttttPP01322313313630,,,133001000PPtttPP试验步骤:添加成员函数,编写成员数代码为publicclassAl_deCasteljau{publicfunctionAl_deCasteljau()3{}//deCasteljau递推算法的实现publicfunctionrecursion(ctrlPts:Array,k:int,i:int,t:Number):Point{if(k==0)returnctrlPts[i];returnaddPoints(multiplyNumToPoint((1-t),recursion(ctrlPts,k-1,i,t)),multiplyNumToPoint(t,recursion(ctrlPts,k-1,i+1,t)));}publicfunctionmultiplyNumToPoint(n:Number,p:Point):Point{returnnewPoint(p.x*n,p.y*n);}publicfunctionaddPoints(p1:Point,p2:Point):Point{returnnewPoint(p1.x+p2.x,p1.y+p2.y);}publicfunctionminusPoints(p1:Point,p2:Point):Point{returnnewPoint(p1.x-p2.x,p1.y-p2.y);}publicfunctionalgorithm_deCasteljau(t:Number,ctrlPts:Array):Point{varsize:int=ctrlPts.length;returnrecursion(ctrlPts,size-1,0,t);}publicfunctionupgradePoints(ctrlPts:Array):Array{varsize:int=ctrlPts.length;varnewPts:Array=newArray();newPts[0]=ctrlPts[0];//i=0for(vari:int=1;isize;++i){varfactor:Number=i/size;newPts[i]=addPoints(multiplyNumToPoint(factor,ctrlPts[i-1]),multiplyNumToPoint((1-factor),ctrlPts[i]));}newPts[size]=ctrlPts[ctrlPts.length-1];//i=n+1returnnewPts;}publicfunctiondowngradePoints(ctrlPts:Array):Array{4varsize:int=ctrlPts.length;varnewPts:Array=newArray();newPts[0]=ctrlPts[0];//i=0for(vari:int=1;isize-1;++i){varfactor:Number=1.0/(size-1-i);newPts[i]=multiplyNumToPoint(factor,minusPoints(multiplyNumToPoint(size-1,ctrlPts[i]),multiplyNumToPoint(i,newPts[i-1])));}returnnewPts;}}编译运行得到如下结果:
本文标题:计算机图形学实验报告-实验3Bezier曲线
链接地址:https://www.777doc.com/doc-5686741 .html