1、程序如下bresenham画线法:#includeconio.hint bresenham(int x0,int y0,int x1,int y1,int color) int x,y,dx,dy,e,i; dx=x1-x0; dy=y1-y0; e=-dx; y=y0; for(x=x0;x=0) y+; e-=2*dx; return 0;int main() initgraph(640,480); bresenham(0,0,500,200,255); while(!kbhit() closegraph();Bresenham画圆法:int circlepoints(int x,int
2、y,int color) putpixel(255+x,255+y,color); putpixel(255+y,255+x,color); putpixel(255-x,255+y,color); putpixel(255+y,255-x,color); putpixel(255-x,255-y,color); putpixel(255-y,255-x,color); putpixel(255+x,255-y,color); putpixel(255-y,255+x,color);int bresenhamcircle(int r,int color) int x,y,d; x=0; y=r
3、; d=3-2*r; while(x=y) circlepoints(x,y,color); if(d0) d+=4*x+6; else d=d+4*(x-y)+10; y-; x+; bresenhamcircle(100,255);五、实验结果记录与分析实验结果如下:6、疑难问题报告2013年10 月29 日9、10 节 实验地点:多边形的填充算法和曲线的绘制 1、实验目的通过本次实验,熟练掌握种子填充算法和多边形扫描线填充算法以及bezier曲线或者B样条曲线的基本绘制算法,能够独立在vc环境下实现任意多边形的填充和一般曲线的绘制,进一步熟悉opengl的语法结构和强大的绘图功能,增强多
4、媒体底层程序绘图能力。1.选择种子填充算法或者多边形的扫描线算法完成多边形的填充。2.选择bezier曲线或者B样条曲线算法完成曲线的绘制。程序如下:多边形扫描线填充算法:/sweep.h#ifndef SWEEP_H#define SWEEP_Hstruct Edge int nxty; int curx;int dx, dy;Edge *nxt;void sweep(int p2, int n, void (*setPixel)(int, int);#endif/sweepline.cpp#include stdio.hglut.h#include sweep.hvoid myInit()
5、;void setPixel(int x, int y);void myDisplay();int main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition (100, 150); glutCreateWindow(SweepLine); glutDisplayFunc(&myDisplay); myInit(); glutMainLoop();void setP
6、ixel(int x, int y) glBegin(GL_POINTS); glVertex2i(x, y); glEnd();void myInit() glClearColor(1.0, 1.0, 1.0, 0.0); glColor3f(0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0);void myDisplay() int i, j; glClear(GL_COLOR_BUFFER_BIT); int p52; p00 = 100; p0
7、1 = 300; p10 = 200; p11 = 50; p20 = 300; p21 = 100; p30 = 400; p31 = 0; p40 = 350; p41 = 470; sweep(p, 5, setPixel); glFlush(); /sweep.cppalgorithmusing namespace std;const int MAXN = 1024;int cpMAXN2, n;inline bool cmp(int i, int j) return cpi1 cpj1 | (cpi1 = cpj1 & cpi0 y2) s, y2); if (y1 y & y dy
8、 cpind1 | (h-dy = cpind1 & h-dx cpind0) break; ph = h; h = h-nxt; data = new Edge; data-curx = px;nxty = cpind1;dx = cpind0 - px;dy = cpind1 - ly;nxt = NULL; if (flag) data-nxty-; if (ph) nxt = ph- ph-nxt = data; else nxt = ely; ely = data;int exMAXNMAXN, neMAXN;inline int abs(int a) return a 0 ? a
9、: -a;void makepoint(int line, Edge *h) int dx = h-dx, dy = h-dy, cnt=0; int x, y, flag=1; if (h-dx)*(h-dy)curx; ynxty; y+) exyney+ = x; cnt += 2*abs(dx); while (cnt=2*abs(dy) cnt -= 2*abs(dy); if (flag) x+; else x-;void sweep(int p2, int nn, void (*setPixel)(int, int) /对所有点按y坐标递增排序,y坐标相等的按x坐标递增排序 n = nn; int i, j, k, ind, nxt, pre; int *num = new intn; /点索引; for (i=0; i pind1) insert(p
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1