Draw Line (Int x1, Int Y1, Int x2, Int Y2) (Float y Int X For (X x1 X x2 X++) //slope 1. (Y Y1+ (x-x1) (Y2-Y1) (x2-x1) Putpixel (X, Round (Y) ) ) )
Draw Line (Int x1, Int Y1, Int x2, Int Y2) (Float y Int X For (X x1 X x2 X++) //slope 1. (Y Y1+ (x-x1) (Y2-Y1) (x2-x1) Putpixel (X, Round (Y) ) ) )
For slope >1 this algorithm gives unsatisfactory results. The solution: symmetry. The assigning of one coordinate axis the name x and other y was an arbitrary choice. slope>1 under one assignment result in slope< 1when the names are reversed.
DDA line drawing algorithm #define ROUND(a) ( (int) (a + 0.5) ) Void lineDDA (int x1,int y1,int x2,int y2) { int dx=x2-x1,dy=y2-y1,steps,k; float xinc,yinc ,x=x1,y=y1; if (abs(dx)>abs(dy)) steps=abs(dx); else
steps=abs(dy);
xinc= dx/(float)steps;
DDA line drawing algorithm cont. yinc= dy/(float)steps; Putpixel(ROUND(x),ROUND(y)); For( k=0;k<steps;k++){
x+= xinc;
y+=yinc;
Putpixel(ROUND(x),ROUND(y)); }
}
Test the sign of an integer parameter whose value is proportional to the distance between the separation of the two pixel positions from the actual path.
yk+1 y yk
d2 d1
Else
pk+1 = pk +2y
next point is(xk + 1, yk+1) pk+1 = pk +2y -2x
NE Q M P(x1,y1) E
P(x1,y1) is selected point, now next is E or NE? Q is the intersection point of a line with column xk+1 . Which side of the line the mid point M lies ? The distance between chosen pixel and actual line is always less than .
y= y1;
y = y + 1;
else
d = d+ ince; }
} }