文档介绍:蒈直线与圆的绘制羆实验目的肁掌握用Besenham法编程实现直线和圆的绘制。会编程绘制虚线、点划线和具有一定宽度的直线。袁实验内容膈用实现直线和圆的绘制螄基本要求:蒃<1)数据输入项为:直线的起点与终点坐标,圆心坐标与半径芁<2)直线与圆输出在中罿附加要求:袅<1)通过用户输入可改变直线的线型<实线、虚线与点划线)薁<2)通过用户输入可改变直线的线宽<用方刷子处理)蚀<3)通过用户输入可改变直线和圆的颜色虿实验所用仪表及设备袆使用实验室提供的PC机。使用VisualC++编程。袄实验步骤膀设计思路蒀设计对话框类蚄设计菜单肂设计CMydrawView类蕿数据成员羆protected:螅doublex0,y0,x1,y1,R。//直线始点与终点、圆的半径膁intcx,cy。//圆的坐标;羈成员函数蚆voidMybline(>。//直线中点Bresenham函数螇voidCirclePoint(doublex,doubley>。//八分子画圆子函数蒃voidMbcircle(>。//圆中点Bresenham函数蚂程序代码莇voidCMydrawView::Mybline(>//中点Bresenham函数b5E2RGbCAP薄{蚁CClientDCdc(this>。肁 COLORREFrgb=RGB(0,255,0>。//定义直线颜色为蓝色膇doublex,y,d,k,t。蚅 x=x0。y=y0。羄if(abs(x1-x0><1e-6>薀 {袇if(y1<y0>螇 {肂 t=y0。y0=y1。y1=t。羀 }蚈for(x=x0,y=y0。y<=y1。y++>(ROUND(x>,ROUND(y>,rgb>。蒅 }荿else莈 {薅 k=(y1-y0>/(x1-x0>。d=-k。薃if(k>1>蝿 {腿if(y1<y0>蚇 {蚁 t=y0。y0=y1。y1=t。蒂 t=x0。x0=x1。x1=t。衿 }蒄 d=1-*k。肄for(x=x0,y=y0。y<=y1。y++>羁 {(ROUND(x>,ROUND(y>,rgb>。蒆if(d>=0>膂 {莁x++。肆d+=1-k。薇 }薄else螀 {袆d+=1。莄 }蚃 }艿 }薆if(0<=k&&k<=1>莆 {螁if(x0>x1>虿 {莇 t=x0。x0=x1。x1=t。蒇 t=y0。y0=y1。y1=t。膄 }肈 d=-k。肇for(x=x0,y=y0。x<x1。x++>芄 {(ROUND(x>,ROUND(y>,rgb>。螂if(d<0>螈 {莆y++。蚄d+=1-k。膁 }薈else肃d-=k。螃 }蚀 }芈if(k>=-1&&k<0>膅 {袁if(x0>x1>肀 {聿 t=x0。x0=x1。x1=t。芆 t=y0。y0=y1。y1=t。芃 }葿 d=--k。蝿for(x=x0,y=y0。x<x1。x++>肃 {(ROUND(x>,ROUND(y>,rgb>。袈if(d>0>蕿 {肅y--。螄d-=1-k。薂 }羆else膆d-=-k。袂 }肁 }螆if(k<-1>羃 {羁if(y0<y1>蒁 {蒇 t=y0。y0=y1。y1=t。羅 t=x0。x0=x1。x1=t。莃 }袀 d=-1--k。芃for(x=x0,y=y0。y>y1。y-->膂 {(ROUND(x>,ROUND(y>,rgb>。莆if(d<0>肄 {羀x++。袀d-=1+k。螅 }螄else羁d-=1。罿 }蒈 }薄 }肃}肇voidCMydrawView::OnMenuitem32772(>//直线菜单函数袈{芅 //TODO:mandhandlercodehere袀InputDlgdlg。葿if((>==IDOK>莇 {肅x0=。袁x1=。薈 y0=。螆 y1=。螅 }羃AfxGetMainWnd(>->SetWindowText("基本图形扫描转换:Mybline">。p1EanqFDPw羀 //RedrawWindow(>。膆Mybline(>。蒆}螀voidCMydrawView::Mbcircle(>//圆中点Bresenham函数DXDiTa9E3d肈{蚅doublex,y,d。羂 d=-R。x=0。y=R。螁for(x=0。x<y。x++>膇 {肅CirclePoint(x,y>。螃if(d<0>袃d+=2*x+3。蕿else螈 {蒃d+=2*(x-y>+5。蚀y--。蚈 }膇 }芃}螂voidCMydrawView::CirclePoint(doublex,dou