Graphical algorithms: DDA (Digital differential Analyzer)
voidLineDDA (intX0,intY0,intXEnd,intyend) { floatDX = xend-x0, dy = yend-y0, steps, K; floatXinerement, yinerement, x = x0, y =y0; if(fabs (DX) >fabs (DY)) {Steps=fabs (DX); } Else{Steps=fabs (DY); } xinerement=float(DX)/float(steps); Yinerement=float(DY)/float(steps); SetPixel (Round (x), round (y)); for(k =0; K < steps; k++) {x+=xinerement; Y+=yinerement; SetPixel (Round (x), round (y)); }}
:
The effect is very poor, the segment part is discontinuous.
2. Bresenham ' s line algorithm
"We need to decide which of the possible pixel positions are closer to the line path at each sample step.
"Testing the sign of an integer parameter whose value was proportional to the difference between the vertical
Vertical separations of the pixel positions from the actual line path.
voidLinebres (intX0,intY0,intXEnd,intyend) { intDX = ABS (xend-x0), DY = ABS (Yend-y0); intp =2* DY-DX; intTwody =2* dy, TWODYMINUSDX =2* (DY-DX); intx, y; if(X0 >xEnd) {x=xEnd; Y=yend; XEnd=x0; } Else{x=x0; Y=y0; } setpixel (x, y); while(X <xEnd) {x++; if(P <0) P+=Twody; Else{y++; P+=TWODYMINUSDX; } setpixel (x, y); }}
Graphics-Linear algorithms