资源描述:
《第5章课后习题参考答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第五章习题参考答案1.试编写一个绘制Bezier曲面的程序。解答:voidCMyView::OnAppBezier(){//TODO:AddyourcommandhandlercodehereInvalidate(true);UpdateWindow();CClientDCdc(this);dc.SetTextColor(RGB(0,0,255));dc.TextOut(160,160,"Bezier曲面");CPenpen1,pen2;pen1.CreatePen(PS_SOLID,1,RGB(100,100,100));pen2.Cre
2、atePen(PS_SOLID,3,RGB(0,0,255));doublea[24][2]={{100,400},{110,300},{130,250},{150,350},{200,300},{210,280},{250,200},{280,250},{300,320},{300,280},{330,180},{360,250},{400,400},{380,320},{410,200},{480,280}};inti,j;dc.SelectObject(&pen2);for(i=0;i<16;i=i+4){dc.MoveTo(a[i]
3、[0],a[i][1]);for(j=0;j<4;j++){dc.LineTo(a[i+j][0],a[i+j][1]);}}for(i=0;i<4;i++){dc.MoveTo(a[i][0],a[i][1]);for(j=0;j<16;j=j+4){dc.LineTo(a[i+j][0],a[i+j][1]);}dc.SelectObject(&pen2);}doublex,y;x=a[0][0];y=a[0][1];dc.MoveTo(x,y);dc.SelectObject(&pen1);doubleu,w;for(u=0;u<1;
4、u=u+0.01){doubleU0=-u*u*u+3*u*u-3*u+1;doubleU1=3*u*u*u-6*u*u+3*u;doubleU2=-3*u*u*u+3*u*u;doubleU3=u*u*u;x=U0*a[0][0]+U1*a[4][0]+U2*a[8][0]+U3*a[12][0];y=U0*a[0][1]+U1*a[4][1]+U2*a[8][1]+U3*a[12][1];dc.MoveTo(x,y);for(w=0;w<1;w=w+0.01){doubleW0=-w*w*w+3*w*w-3*w+1;doubleW1=3
5、*w*w*w-6*w*w+3*w;doubleW2=-3*w*w*w+3*w*w;doubleW3=w*w*w;x=((U0*a[0][0]+U1*a[4][0]+U2*a[8][0]+U3*a[12][0])*W0+(U0*a[1][0]+U1*a[5][0]+U2*a[9][0]+U3*a[13][0])*W1+(U0*a[2][0]+U1*a[6][0]+U2*a[10][0]+U3*a[14][0])*W2+(U0*a[3][0]+U1*a[7][0]+U2*a[11][0]+U3*a[15][0])*W3);y=((U0*a[0]
6、[1]+U1*a[4][1]+U2*a[8][1]+U3*a[12][1])*W0+(U0*a[1][1]+U1*a[5][1]+U2*a[9][1]+U3*a[13][1])*W1+(U0*a[2][1]+U1*a[6][1]+U2*a[10][1]+U3*a[14][1])*W2+(U0*a[3][1]+U1*a[7][1]+U2*a[11][1]+U3*a[15][1])*W3);dc.LineTo(x,y);}}for(w=0;w<1;w=w+0.01){doubleW0=-w*w*w+3*w*w-3*w+1;doubleW1=3*
7、w*w*w-6*w*w+3*w;doubleW2=-3*w*w*w+3*w*w;doubleW3=w*w*w;x=W0*a[0][0]+W1*a[1][0]+W2*a[2][0]+W3*a[3][0];y=W0*a[0][1]+W1*a[1][1]+W2*a[2][1]+W3*a[3][1];dc.MoveTo(x,y);for(u=0;u<1;u=u+0.01){doubleU0=-u*u*u+3*u*u-3*u+1;doubleU1=3*u*u*u-6*u*u+3*u;doubleU2=-3*u*u*u+3*u*u;doubleU3=u
8、*u*u;x=((U0*a[0][0]+U1*a[4][0]+U2*a[8][0]+U3*a[12][0])*W0+(U0*a[1][0]+U1*a[5][0]+U2*a[9][