实验四Bezier曲线生成算法实现_第1页
实验四Bezier曲线生成算法实现_第2页
实验四Bezier曲线生成算法实现_第3页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、计算机图形学实验报告(实验四 ,.Bezier曲线生成算法实现一、实验目的及要求三次 Bezier曲线及 de Casteljau算法以及 b样条曲线二、理论基础详见教材!三、算法设计与分析Bezier 曲线生成算法int degree=3,i,x,y;float t;float coeff_x4=50.0,200.0,200.0,500.0;float coeff_y4=50.0,300.0,50.0,200.0;pDC->MoveTo(coeff_x0,coeff_y0; for(i=1;i<=3;i+ pDC->LineTo(coeff_xi,coeff_yi;for(

2、t=0;t<=1;t+=0.001x=hornbez(degree,coeff_x,t; y=hornbez(degree,coeff_y,t; pDC->SetPixel(x,y,RGB(0,0,0;float CMy2View:hornbez(int degree,float coeff,float tint i,n_choose_i;float fact,t1,aux;t1=1.0-t;fact=1.0;n_choose_i=1;aux=coeff0*t1;for(i=1;ifact =fact*t;n_choose_i=n_choose_i*(degree-i+1/i;au

3、x=(aux+fact*n_choose_i*coeffi*t1;aux=aux+fact*t*coeffdegree;return aux;de Casteljau 算法void CTuView:bezpoint(int degree,int npoints,float *coeff,float points float t,delt;int i;delt=1.0/(floatnpoints;t=0.0;for (i=0;ipointsi=decas(degree,coeff,t;t=t+delt;float CTuView:decas(int degree,float *coeff,flo

4、at t int r,i;float t1;float coeffa10;t1=1.0-t;for (i=0;i<=degree;i+coeffai=coeffi; for(r=1;r<=degree;r+for (i=0;i<=degree-r;i+ coeffai=t1*coeffai+t*coeffai+1;return coeffa0;主函数:void CTuView:OnDraw(CDC* pDCCTuDoc* pDoc = GetDocument(; ASSERT_VALID(pDoc;/ TODO: add draw code for native data h

5、ereint degree=5,npoints=1000,i;float coeffx=10,40,265,300,400,500;float coeffy=20,130,160,90,300,100;float points11000,points21000;for (i=0;ipDC->MoveTo(intcoeffxi,(intcoeffyi;pDC->LineTo (intcoeffxi+1,(intcoeffyi+1;bezpoint(degree,npoints,coeffx,points1;bezpoint(degree,npoints,coeffy,points2;

6、for(i=0;ipDC->SetPixel(intpoints1i,(intpoints2i,RGB(123,123,123;B 样条曲线void CBView:bsp(int degree,int l,float *coeff,float*knot,int dense,float *points,int *point_numint i,ii;float u;*point_num=0;for(i=degree-1;iif(knoti+1>knoti for(ii=0;iiu=knoti+ii*(knoti+1-knoti/dense; points*point_num=deboo

7、r(degree,coeff,knot,u,i; *point_num=(*point_num+1;float CBView:deboor(int degree,float *coeff,float *knot,float u,int iint k,j;float t1,t2;float coeffa30;for (j=i-degree+1;j<=i+1;j+ coeffaj=coeffj;for (k=1;k<=degree;k+ for(j=i+1;j>=i-degree+k+1;j- t1=(knotj+degree-k-u/(knotj+degree-k-knotj-

8、1; t2=1.0-t1;coeffaj=t1*coeffaj-1+t2*coeffaj;return coeffai+1;主函数:void CBView:OnDraw(CDC* pDCCBDoc* pDoc = GetDocument(; ASSERT_VALID(pDoc;/ TODO: add draw code for native data here int k,n;int degree,i,a;int dense=290,l=5;float coeffx=10,40,265,300,400,500,600;float coeffy=20,130,160,90,300,100,300

9、; float points12000,points22000;float knot=0,0,0,0,0,1,2,2,2,2,2;int *point_num; k=5,n=5;/*n+1 个点 */ degree=5;a=0; point_num=&a;for (i=0;i<6;i+ pDC->MoveTo(intcoeffxi,(intcoeffyi; pDC->LineTo (intcoeffxi+1,(intcoeffyi+1;bsp(degree,l,coeffx,knot,dense,points1,point_num;bsp(degree,l,coeffy,knot,dense,points2,point_num;for(i=0;i<2000;i+pDC->SetPixel(intpoints1i,(intpoints2i,RGB(123,123,12

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论