DDABresenhamVisualCDDABresenham1p753.1ç2p753.53MFCCDCSetPixel()LineToPolylineEllipse45project/6DDABresenhamVisualC++6.01VCMFCAppwizardSDICG121222Finish3CGView.cppCCGViewinclude“math.h”//fabsvoidDDALine(intx0,inty0,intx1,inty1,COLORREFcolor)VCClassViewCCGView3AddMemberFunction…4DDALine344voidDDALine(intx0,inty0,intx1,inty1,COLORREFcolor)DDAP30~P31SetpixelCDC*pDC=this-GetDC();pDC-SetPixel(int(x+0.5),int(y+0.5),color);SetPixel(int(x+0.5),int(y+0.5),color);BresenhamSetPixel53CGView.cppCCGViewvoidBresenham_Line(intx0,inty0,intx1,inty1,COLORREFcolor)P33Bresenham4SetpixelOnDraw2DDABresenhamvoidCZhangchenchuView::DDALine(intx0,inty0,intx1,inty1,COLORREFcolor){inti;floatdx,dy,length,x,y;if(fabs(x1-x0)=fabs(y1-y0))length=fabs(x1-x0);elselength=fabs(y1-y0);dx=(x1-x0)/length;dy=(y1-y0)/length;i=1;x=x0;y=y0;while(i=length){CDC*pDC=this-GetDC();pDC-SetPixel(int(x+0.5),int(y+0.5),color);x=x+dx;y=y+dy;i++;}}voidCZhangchenchuView::Bresenham_Line(intx0,inty0,intx1,inty1,intcolor){intdx,dy,e,i,x,y;dx=x1-x0;dy=y1-y0;e=2*dy-dx;x=x0;y=y0;for(i=0;i=dx;i++){CDC*pDC=this-GetDC();pDC-SetPixel(x,y,color);if(e=0){y++;e=e-2*dx;}elsex++;e=e+2*dy;}}1OnDrawpublicvoiddrawLines(float[]pts,Paintpaint)pts4paint2|k|1k0k1k1y1Bresenhamx1.xyk0xy113CDC4P733.51VisualCDDABresenhamDDABresenham2DDADDAy=kx+b11.2.xXyY3.MaxSteps=maxXY;X=YXXYY/MaxSteps;4.5.1MaxStepsx,yxyx,yBresenhamDDADDAxyk|k|1xk|k|1y1LineToPolyline2VisualC++VisualC++MSDN