1、1,Midpoint Line Algorithm (13),2,此时,可利用两候选点的中点与直线的位置关系,选出更接近直线的候选点,Midpoint Line Algorithm (14),3,点/线位置关系的判别计算,采用增量计算方法优化判别公式的计算,Midpoint Line Algorithm (15),4,例:用中点画线法光栅化一条连接两点(0,0)和(5,2)的直 线段,写出计算过程。,Example(1),5,P(xi,yir),Bresenham 判别方法示意图,Bresenham Line Algorithm(1),P(xi,yi),(xi+1,yi+1),6,Bresen
2、ham Line Algorithm(1),?: how to calculate efficiently?,increment,7,Homework,1.请用增量式方法推导扫描转换斜率00)的线段的Bresenham算法,写出推导过程。2.如何消除上述算法中的浮点数?并试将该算法推广到可以扫描转换任意直线段。,8,Bresenham Line Algorithm(3),9,Bresenham Line Algorithm(4),Initializtion:,Iteration:,10,Bresenham Line Algorithm(5),Eliminate fraction:在判别式两边同
3、乘以2x,Initializtion:,Iteration:,11,Additional Issues(1),Endpoint order: make sure that a line from P0 to P1 contains the same set of pixels as the line from P1 to P0,12,Additional Issues(2),Starting at the edge of a clip rectangle,Fig. 3.10 Starting the line at a clip boundary. (a) Intersection with
4、a vertical edge (b) Intersection with a horizontal edge (gray pixels are on the line but are outside the clip rectangle).,13,Additional Issues(3),Varying the intensity of a line as a function of slopeOutline primitives composed of lines,14,SCAN CONVERTING CIRCLES,Original definition,To found pixels
5、which lie on or nearest to the arc; The maximum number pixels that we can do.,15,Representation of circle,equivalent definitions,16,Inefficient algorithms,17,(xc,yc),(x,y),(x,y),(x+ xc,y+ yc),Representation of circle,18,Representation of circle,translated to the origin by integer amounts scan conver
6、ted with pixels written with the appropriate offset.,19,(x,y),Origin,(x,-y),(-x,y),(-x,-y),X-axis,y=x line,(y,x),Y-axis,Characteristic of circles,Eight-Way Symmetry,20,The problem,To find the set of pixels that close to the arc:,The tangent slope satisfies:,21,Characteristic of circles,22,Principle
7、of midpoint algorithm,Decision variable:,?: how to calculate dk efficiently?,increment,23,Cont.,Float point!,24,Cont.,Let:,Alternative method:,Then the initialization becomes,25,Summary,26,Second-order difference,提高计算效率,类似地:,27,Homework,用中点算法的二级增量算法递推计算扫描转换圆心在(2,5),半径为11的圆的第一个1/4圆弧的过程。,28,Answer,put
8、pixel(x+2,y+5), (y+2,x+5),29,中点画圆算法(1),原理:,30,中点画圆算法(2),定义圆函数:,特点:,引入判别参数:,31,中点画圆算法(3),算法描述: (假设X方向的步长为1),问题:如何快速计算判别参数的值?,32,中点画圆算法(4),使用增量计算方法改进判别参数的计算效率,33,中点画圆算法(5),关于计算效率的考虑:消除浮点运算 考虑:点的选择只与判别量的符号相关 引入:,另一种方式:,34,中点画圆算法(6),35,中点画圆算法(7),提高计算效率,类似地:,36,中点画圆算法(8),Void MidPointCircle(int r, int color) int x,y,d;x=0;y=r;d=1-r;delta1=3;delta2=5-2r;putpixel(x,y,color);while(yx)if(d0) d+=delta1; delta2+=2; else d+=delta2; delta2+=4; y-delta1+=2;x+;putpixel (x,y,color);CirclePoints(x,y,color);/while /end,