Dda_-line algorithm for differential plotting
In step axis = 1 pixels, calculate y=kx + B and draw pixel points (x, round (y)).
That is, the step coordinates increase by 1, and the other coordinates grow K or 1/k.
The procedure is as follows:
1 //numerical differential algorithm dda2 voidCcgprojectworkview::D da_line (Const intStartpos[],Const intEndpos[],Const floatlinecolor[])3 {4 Glpushmatrix ();5 //Draw a line6 LongDeltx, Delty, Maxstep;7Deltx = endpos[0]-startpos[0];8Delty = endpos[1]-startpos[1];9Maxstep =Max (ABS (DELTX), ABS (delty));Ten //calculates the direction of the step unit, that is, the slope growth Unit in two directions One floatXstepunion =float(DELTX)/Maxstep; A floatYstepunion =float(delty)/Maxstep; - -glcolor3f (linecolor[0], linecolor[1], linecolor[2]); the Glbegin (gl_points); - - floatx, y;//plotted coordinate points -x = (float) startpos[0]; +y = (float) startpos[1]; - + //cyclic stepping in two directions A for(LongI=1; i<=maxstep; i++) at { -x = x +xstepunion; -y = y +ystepunion; -glvertex3f ((int) x, (int) Y,0); - } - glend (); in Glpopmatrix (); -}
Dda_-line algorithm for differential plotting