您好,欢迎访问三七文档
实验三课程名称:计算机图形学实验名称:曲线的生成实验日期:2015.4.22班级:数媒1302姓名:徐进都学号1030513230仪器编号:××一、实验目的和要求1、掌握Hermite曲线生成算法;2、掌握Bezier曲线的定义生成算法、离散生成算法,了解Bezier曲面的生成算法;3、掌握B样条曲线的定义生成算法,了解B样条曲面。二、实验内容1、已知空间点两点P0(-40.0,-40.0,0.0)、P1(10.0,-200.0,0.0)及该点上的切向量分别为R0(30.0,240.0,0.0),R1(30.0,-240.0,0.0)。运行附件程序,分析理解Hermite曲线生成算法。2、已知空间四点P0(-40.0,-40.0,0.0)、P1(-10.0,200.0,0.0)、P2(10.0,-200.0,0.0)、P3(40.0,40.0,0.0),参照1的程序并根据Bezier曲线的定义编程绘制三次Bezier曲线。3、已知空间四点P0(-40.0,-40.0,0.0)、P1(-10.0,200.0,0.0)、P2(10.0,-200.0,0.0)、P3(40.0,40.0,0.0),参照1的程序并根据B样条曲线的定义绘制三次B样条曲线。4、思考如何利用实验一到实验三所学的知识,实现绘制自己的姓名。(该题作为平时成绩的单独加分项)三、实验步骤P(t)=(1-t)3p0+3t(1-t)2p1+3t2(1-t)p2+t3p30t1[-13-31][p0]P(t)=[t3t2t1][3630][p1][-3300][p2][1000][p3]四、程序清单#includestdio.h#includegl\glut.h#includestdlib.h#includemath.hGLsizeiwinWidth=600,winHeight=600;GLfloatxwcMin=-50,xwcMax=50;GLfloatywcMin=-50,ywcMax=50;//GLfloatu[11]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};GLfloatu[8]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0};classwcPt3D{public:GLfloatx,y,z;};voidint(){glClearColor(1.0,1.0,1.0,0.0);}voidplotPoint(wcPt3DbCurvePt){glBegin(GL_POINTS);glVertex2f(bCurvePt.x,bCurvePt.y);glEnd();}GLfloatBsum(GLfloatn,GLintk,GLintd){if(d==1)if(n=u[k]&&nu[k+1]){return1.0;}elsereturn0.0;else{GLfloati=Bsum(n,k,d-1);GLfloatj=Bsum(n,k+1,d-1);GLfloatx,y;if(u[k+d-1]-u[k]!=0)x=(n-u[k])/(u[k+d-1]-u[k]);elsex=0.0;if(u[k+d]-u[k+1]!=0)y=(u[k+d]-n)/(u[k+d]-u[k+1]);elsey=0.0;return(x*i+y*j);}}voidcomputeBPt(wcPt3D*bPt,wcPt3D*ctrlPts,GLfloatn,GLintd,GLintnCtrlPts){bPt-x=bPt-y=bPt-z=0.0;GLfloatBkd;GLinti;for(i=0;inCtrlPts;i++){Bkd=Bsum(n,i,d);bPt-x+=Bkd*ctrlPts[i].x;bPt-y+=Bkd*ctrlPts[i].y;bPt-z+=Bkd*ctrlPts[i].z;}}voidBline(wcPt3D*ctrlPts,GLintnCtrlPts,GLintnBCurvePts,GLintd){wcPt3DbCurvePt;GLfloatn;GLinti;for(i=0;inBCurvePts;i++){n=(GLfloat(i)*9.0)GLfloat(nBCurvePts);//n=(GLfloat(i)*7.0)/GLfloat(nBCurvePts);computeBPt(&bCurvePt,ctrlPts,n,d,nCtrlPts);plotPoint(bCurvePt);}}voiddisplayFcn(){GLinti;GLintnCtrlPts=4,nBCurvePts=1000,d=4;//GLintnCtrlPts=7,nBCurvePts=1000,d=4;//wcPt3DctrlPts[7]={{0.0,-40.0,0.0},{-35.0,20.0,0.0},{-15.0,30.0,0.0},//{0.0,25.0,0.0},{15.0,30.0,0.0},{35.0,20.0,0.0},{0.0,-40.0,0.0}};wcPt3DctrlPts[4]={{-40.0,-40.0,0.0},{-10.0,50.0,0.0},{10.0,-50.0,0.0},{40.0,40.0,0.0}};glClear(GL_COLOR_BUFFER_BIT);glPointSize(4);glColor3f(1.0,0.0,0.0);Bline(ctrlPts,nCtrlPts,nBCurvePts,d);glPointSize(10);glColor3f(0.0,0.0,0.0);for(i=0;inCtrlPts;i++){plotPoint(ctrlPts[i]);}glFlush();}voidwinReshapeFcn(GLintnewWidth,GLintnewHeight){glViewport(0,0,newWidth,newHeight);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(xwcMin,xwcMax,ywcMin,ywcMax);glClear(GL_COLOR_BUFFER_BIT);}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(50,50);glutInitWindowSize(winWidth,winHeight);glutCreateWindow(B样条曲线);init();glutDisplayFunc(displayFcn);glutReshapeFunc(winReshapeFcn);glutMainLoop();return0;}五、实验体会这两个曲线绘制的实验还是比较有难度,很多地方要向同学请教或者是上网查阅资料,其中多次不能运行成功,经过反复修改才画出来,收获很多。
本文标题:计算机图形学实验3
链接地址:https://www.777doc.com/doc-5547815 .html