资源描述:
《计算机图形学实验答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验一、中点画直线算法#include#includevoidMidpointLine1(intx0,inty0,intx1,inty1,intcolor){inta,b,d1,d2,d,x,y;a=y0-y1;b=x1-x0;d=2*a+b;d1=2*a;d2=2*(a+b);x=x0;y=y0;putpixel(x,y,color);while(x2、dMidpointLine2(intx0,inty0,intx1,inty1,intcolor){inta,b,d1,d2,d,x,y;a=y0-y1;b=x1-x0;d=2*a-b;d1=2*a;d2=2*(a-b);x=x0;y=y0;putpixel(x,y,color);while(x3、ta,b,d1,d2,d,x,y;a=y0-y1;b=x1-x0;d=a+2*b;d1=2*b;d2=2*(a+b);x=x0;y=y0;putpixel(x,y,color);while(x4、=2*(a-b);x=x0;y=y0;putpixel(x,y,color);while(x5、1,y1,t;floatk;intgdriver=DETECT,gmode;scanf("%d%d%d%d",&x0,&y0,&x1,&y1);initgraph(&gdriver,&gmode,“c:\tc\bgi");if(x0==x1)LineV(x0,y0,y1,WHITE);else{if(x1=0&&k<1)MidpointLine1(x0,y0,x1,y1,WHITE);els
6、eif(k<0&&k>=-1)MidpointLine2(x0,y0,x1,y1,WHITE);elseif(k>1)MidpointLine3(x0,y0,x1,y1,WHITE);elseMidpointLine4(x0,y0,x1,y1,WHITE);}getch();closegraph();}二、中点画圆#include#includevoidMidpoint_circle(r,color)intr,color;{intx,y,deltax,deltay,e;x=0;y=r;e
7、=1-r;deltax=3;deltay=2-r-r;putpixel(x,y,color);while(x8、l(y+320,x+240,color);putpixel(-y+320,x+240,color);putpixel(y+320,-x+240,color);putpixel(-y+320,-x+240,color);}}intmain(){intr0,colo