大佬教程收集整理的这篇文章主要介绍了直线DDA,直线和圆的Bresenham算法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_772_32@
// 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); }
以上是大佬教程为你收集整理的直线DDA,直线和圆的Bresenham算法全部内容,希望文章能够帮你解决直线DDA,直线和圆的Bresenham算法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。