直线DDA,直线和圆的Bresenham算法
发布时间:2020-12-14 05:57:45 所属栏目:Windows 来源:网络整理
导读:? ? ? ? ? ? ? ? ? // DDA.cpp : 定义控制台应用程序的入口点。 // #include " stdafx.h " #include Windows.h #include graphics.h #include conio.h #include math.h void dda_line( int xa, int ya, int xb, int yb, int c); int main( int argc,_TCHAR*
? ? ? ? ? ? ? ? ? // DDA.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<Windows.h> #include<graphics.h> #include<conio.h> #include<math.h> void dda_line(int xa,int ya,int xb,int yb,int c); int main(int argc,_TCHAR* argv[]) { int gd=DETECT,gm; /*图形屏幕初始化*/ initgraph(&gd,&gm,""); dda_line(100,100,200,255); getch(); closegraph(); return 0; } void dda_line(int xa,int c) { float delta_x,delta_y,x,y; int dx,dy,steps,k; dx=xb-xa; dy=yb-ya; if(abs(dx)>abs(dy))steps=abs(dx); else steps=abs(dy); delta_x=(float)dx/(float)steps; delta_y=(float)dy/(float)steps; x=xa; y=ya; putpixel(x,y,c); for(k=1;k<=steps;k++) { x+=delta_x; y+=delta_y; putpixel(x,c); } } ? ? ? ? ? ? ? ? ? #include "stdafx.h" #include<Windows.h> #include<graphics.h> #include<conio.h> #include<math.h> void lineBres(int x0,int y0,int xEnd,int yEnd,""); lineBres(0,0,255); getch(); closegraph(); return 0; } void lineBres(int x0,int c) { int dx = (int)fabs(double((xEnd-x0))); int dy = (int)fabs(double(yEnd-y0)); int p =2* dy-dx; int twoDy = 2*dy,twoDyMinusDx = 2* (dy - dx); int x,y; if (x0>xEnd) { x=xEnd; y=yEnd; xEnd=x0; } else{ x=x0; y=y0; } putpixel (x,c); while (x<xEnd) { x++; if(p<0) p+=twoDy; else{ y++; p+=twoDyMinusDx; } putpixel (x,c); } } ? ? ? ? ? ? ? ? ? ? ? ? #include "stdafx.h" #include<Windows.h> #include<graphics.h> #include<conio.h> #include<math.h> void CircleBres(int xc,int yc,int radious,int c); void plot_circle_points(int xc,int x,int y,""); CircleBres(100,20,255); getch(); closegraph(); return 0; } void CircleBres(int xc,int c) { int x,p; x=0; y=radious; p=3-2*radious; while(x<y){ plot_circle_points(xc,yc,c); if(p<0) p=p+4*x+6; else{ p=p+4*(x-y)+10; y-=1; } x+=1; } if(x==y){ plot_circle_points(xc,c); } } void plot_circle_points(int xc,int c) { putpixel(xc+x,yc+y,c); putpixel(xc-x,c); putpixel(xc+x,yc-y,c); putpixel(xc+y,yc+x,c); putpixel(xc-y,yc-x,c); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- chmod如何为windows工作?
- active-directory – 降级DC的问题,仍然在目录中的故障SBS2
- 适用于Windows的免费WebDAV客户端?
- 走进windows编程的世界-----消息处理函数(1)
- 在Windows 8中给Java应用程序一个Metro Look and Feel
- windows – 删除在同一进程中为独占访问而打开的文件
- 如何在Windows PowerShell中进行屏幕截图?
- windows-server-2008 – 如何使用组策略设置默认的Internet
- windows-server-2008 – 强制与特定服务器的RDP连接
- windows-vista – 使用远程桌面时Windows Vista默认打印机更