资源描述:
《计算机图形学实验答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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、(x,y,color);}}voidMidpointLine2(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、tx0,inty0,intx1,inty1,intcolor){inta,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、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(x5、0=y1;y1=t;}for(y=y0;y<=y1;y++)putpixel(x,y,color);}main(){intx0,y0,x1,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(x16、0=y1;y1=t;}k=(float)(y1-y0)/(x1-x0);if(k>=0&&k<1)MidpointLine1(x0,y0,x1,y1,WHITE);elseif(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();}二、中点画圆#includ
7、e#includevoidMidpoint_circle(r,color)intr,color;{intx,y,deltax,deltay,e;x=0;y=r;e=1-r;deltax=3;deltay=2-r-r;putpixel(x,y,color);while(x8、ixel(x+320,y+240,color);putpixel(-x+320,y+240,color);putpixel(x+320,-y+240,color);putpixel(-x+320,-y+240,color);putpixel(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