Dda_-line algorithm for differential plotting

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.